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
References
Microsoft Anti-XSS Library 4.0, http://www.microsoft.com/downloads/en/details.aspx?FamilyID=F4CD231B-7E06-445B-BEC7-343E5884E651
Nerdbank, http://blog.nerdbank.net/2009/05/uriescapedatapath-and.html
StackOverflow, http://stackoverflow.com/questions/36315/alternative-to-httputility-for-net-3-5-sp1-client-framework
URL Encode in .Net
C#: (ASP .Net)
System.Web.HttpUtility.UrlEncode()
C#: (Client/Server Environment)
Uri.EscapeUriString()
References
MSDN, WebUtility Classhttp://msdn.microsoft.com/en-us/library/system.net.webutility.aspx
MSDN, Uri Classhttp://msdn.microsoft.com/en-us/library/system.uri.escapeuristring.aspx
MSDN blogs, http://blogs.msdn.com/b/yangxind/archive/2006/11/09/don-t-use-net-system-uri-unescapedatastring-in-url-decoding.aspx