HTMLEncode in Winforms
12,426
Solution 1
try
System.Web.HttpUtility.HtmlEncode(foo);
you will need to add a reference to System.Web.dll
Solution 2
You may also Try Uri.EscapeDataString(STRING_HERE) (No reference required), works in Asp.net & WinForms.
Comments
-
Raj More almost 2 years
I have a Winform application in which I am checking if a fully qualified file name
c:\somefolder\my file name.txt
exists in the XML.Unfortunately, the XML holds the strings html encoded so
c:\somefolder\my file name.txt
becomesc:/somefolder/my%20file%20name.txt
(not the change from backslash to forwardslash, and the %20 instead of blankspace).How do I HTMLEncode strings in my winform app?
-
Jonathan Wood almost 10 yearsI believe that escapes a URL, not HTML.
-
bernhof over 9 years
HttpUtility
usesWebUtility.HtmlEncode
internally, which is part ofSystem.Net
namespace. You don't need the System.Web reference, at least in .NET 4.5. See referencesource.microsoft.com/System.Web/R/…