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, http://www.microsoft.com/downloads/en/details.aspx?FamilyID=F4CD231B-7E06-445B-BEC7-343E5884E651
Posted on February 14, 2011, in Programming & Development and tagged decode, encode, url, url decode, urldecode, urlencode, winforms, wpf. Bookmark the permalink. Leave a comment.
Leave a comment