This project has moved. For the latest updates, please go here.

Escape characters while building html

Apr 23, 2015 at 11:29 PM
Hello All,

I am using the HtmltoOpenXml dll for generating the word document. Let me tell you that this is a great dll and it generates the word document very neatly as required.

I am facing one issue when generating the html content for the word document. Html template is designed on the fly in C# code but the values in the html content is sourced from the database. Those values contain " and ' characters in the text. So generating the html gets failed when I have these characters in the text.

Can anyone let me know is there a solution for this problem.
Apr 24, 2015 at 7:32 AM

This problem is very tied to your way to build your Html.
Similarly to what you should do if creating an Xml "by-hand", you will have to escape the quotes.
Don't forget to encode also "<" and ">" inside the tags (see related issue)

You can use .net built-in utilities: HttpUtility.HtmlEncode and HttpUtility.HtmlAttributeEncode.