Blog Archives

URL Decode in WPF

Crossing from web to forms development you may notice System.Web is not available. You could extract it from the GAC, but would suffer from having to manually update it moving forward.

One solution on the web suggested using Microsoft.XSS library (which is up to version 4.0 at the time of this article).

This would work, but there are some differences in string conversion, especially regarding the “+” and “~” character between using the Web UrlEncode/UrlDecode found in the XSS library or using the Uri method illustrated below.

See references for links to XSS and/or information regarding the differences on how these strings are encoded differently with each method.

Uri videouri = new Uri(AppDomain.CurrentDomain.BaseDirectory + "../../Videos/directory/player.htm");

            string videourl = Uri.UnescapeDataString(videouri.ToString());

            webBrowser1.Navigate(videourl); //can actually accept uri or string

Microsoft Anti-XSS Library 4.0,