47

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?

animuson
  • 50,765
  • 27
  • 132
  • 142
miccet
  • 1,840
  • 3
  • 19
  • 25

7 Answers7

96

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

bizon
  • 2,346
  • 2
  • 23
  • 27
27

You can use System.Net.WebUtility.HtmlDecode:

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

Rup
  • 31,518
  • 9
  • 83
  • 102
kirankumar
  • 271
  • 3
  • 2
24

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.

Jon Skeet
  • 1,261,211
  • 792
  • 8,724
  • 8,929
  • I have tripped on this before. I forgot the reference, thought a "using" would do. Thanks! – miccet Apr 03 '09 at 06:07
  • 13
    The issue with that is that you can't use the .NET 3.5 Client profile with your .NET app so your XP users can avoid the 150mb download and go for the smaller 28mb one. Best to avoid the System.Web namespace if you can. – Zac Bowling Jan 28 '10 at 05:25
  • 2
    I second that, It´s silly a subset of these methods couldn't be provided in a seperate assembly available for the client profile installation.. i find myself quite often needing them in simple client apps. – Almund Dec 18 '10 at 22:53
  • 3
    @Almund: Check my answer. They did it. – bizon Jan 03 '12 at 14:56
7

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;" )

Steve Eisner
  • 2,005
  • 23
  • 34
0

mybe it can help in winforms :

System.Uri.EscapeUriString(plainText);
Simko
  • 45
  • 8
0

To use the methods that are in the .NET framework you must use the System.Web namespace to get the HtmlDecode method.

Yes, you could write your own method to do it, but that wouldn't make a lot of sense.

Just add the reference to system.web.

Mitchel Sellers
  • 58,921
  • 13
  • 103
  • 170
-1

You can use HttpUtility.UrlDecode or HttpUtility.HtmlDecode

Curt
  • 94,964
  • 60
  • 257
  • 340
  • 5
    Since the question was how to do this Without the System.Web assembly I´m afraid this isn't much help.. – Almund Dec 18 '10 at 22:54