C# HTMLDecode without System.Web possible?

白昼怎懂夜的黑 提交于 2019-11-30 01:44:29

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

kirankumar

You can use System.Net.WebUtility.HtmlDecode:

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

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.

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

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.

mybe it can help in winforms :

System.Uri.EscapeUriString(plainText);
pathachiever11

You can use HttpUtility.UrlDecode or HttpUtility.HtmlDecode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!