Search code examples
c#.nethtml-encode

Html encoding in .NET class library


I have a utility class for sending emails. The emails are generated as html.

I'm having problems with encoding special characters which aren't getting displayed correctly.

However, I can't work out how to use HtmlEncode as I don't have a current HttpContext. Is there a .Net class which will translate special characters to html codes without running under Asp.Net?

I hope that makes sense, I'm a bit flaky about how all this stuff works. Thanks!


Solution

  • You can import the System.Web namespace and use the HttpUtility class. Altohugh it's a Web assembly I don't think it's neccesary to be running under a Web environment for it to work.