Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# HTMLDecode without System.Web possible?

Tags:

c#

html-encode

I know there are different methods in the System.Web namespace for decoding html entities (such as "%20" for space). I'm building a Winforms application however, but needs to deal with html encoded strings. Basically I have the iTunes Library XML file and need to decode the URLs in there to check the files.

Is this possible without the System.Web namespace?

like image 763
miccet Avatar asked Apr 02 '09 21:04

miccet


4 Answers

Developers who need to use System.Web.HttpUtility in their client apps and had to reference System.Web.dll and therefore target NET4 full (System.Web.dll is in Full) , can now target the NET4 Client Profile by using the new System.Net.WebUtility class which is in System.dll (System.dll is in NET4 Client Profile). System.Net.WebUtility includes HtmlEncode and HtmlDecode. Url encoding can be accomplished using the System.Uri class (also in System.dll).

From http://blogs.msdn.com/b/jgoldb/archive/2010/04/12/what-s-new-in-net-framework-4-client-profile-rtm.aspx

like image 185
bizon Avatar answered Oct 10 '22 13:10

bizon


You can use System.Net.WebUtility.HtmlDecode:

Converts a string that has been HTML-encoded for HTTP transmission into a decoded string.

like image 38
kirankumar Avatar answered Oct 10 '22 11:10

kirankumar


Just because you're writing a Windows Forms app doesn't stop you from using System.Web. Just add a reference to System.Web.dll.

like image 24
Jon Skeet Avatar answered Oct 10 '22 12:10

Jon Skeet


See this article if you're still curious how to do this without System.Web. It offers a solution for URI decoding (which is really what you're decoding, not HTML entities which are something like "&emdash;" )

like image 8
Steve Eisner Avatar answered Oct 10 '22 13:10

Steve Eisner