Alternative to System.Web.HttpUtility.HtmlEncode/Decode?

Jörg Battermann picture Jörg Battermann · May 6, 2010 · Viewed 9.2k times · Source

Is there any 'slimmer' alternative to the System.Web.HttpUtility.HtmlEncode/.Decode functions in .net 3.5 (sp1)? A separate library is fine.. or even 'wanted', at least something that does not pull in a 'whole new world' of dependencies that System.Web requires.

I only want to convert a normal string into its xml/xhtml compliant equivalent (& back).

Answer

user90843 picture user90843 · May 6, 2010

In .NET Framework 4.0, System.Net.WebUtility.HtmlEncode perhaps? Do note that this class is located in System.dll and not System.Web.dll.