Html encoding in .NET class library

fearofawhackplanet picture fearofawhackplanet · Nov 19, 2010 · Viewed 9.9k times · Source

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!

Answer

Dean Taylor picture Dean Taylor · Nov 19, 2010

I believe System.Net.WebUtility.HtmlEncode will provide this functionality. MSDN reference for WebUtility.HTMLEncode