Html to Word File - C#

Html to Word File - C#

code snippet

c#
public void Wordfile(string strHtml, string strFileName)
{
        try
        {
            StringBuilder StrLocLetterText = new StringBuilder();
            String ObjLocHtml1 = "<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:word\" xmlns=\"http://www.w3.org/TR/REC-html40\">";
            ObjLocHtml1 += "<head></head><body>";
            String ObjLocHtml2 = "</body></html>";

            StrLocLetterText.Append(ObjLocHtml1);
            StrLocLetterText.Append(strHtml);
            StrLocLetterText.Append(ObjLocHtml2);

            Response.Clear();
            Response.Charset = "";
            Response.ContentType = "application/msword";
            Response.AddHeader("Content-Disposition", string.Format("inline;filename={0}.doc", strFileName));
            Response.Write(StrLocLetterText);
            Response.End();
            Response.Flush();
        }
        catch (Exception ex) { throw ex; }
}

"The secret of getting ahead is getting started"

Contact me!

Have questions? Feel free to use the form or send me an email with any questions.

I will be responsive to your requests and your questions.