I am using this code:
///
///
///
///
///
///
public void ServeAsDoc(System.Web.UI.Page webPage, Boolean download, String FileName)
{
try
{
string htmlString = GetHtmlForPage();
webPage.Response.Buffer = true;
webPage.Response.Clear();
webPage.Response.ContentType = "application/vnd.ms-word"; //application/octet-stream
webPage.Response.ContentEncoding = System.Text.UnicodeEncoding.UTF8;
webPage.Response.Charset = "UTF-8";
webPage.Response.AddHeader("Content-Disposition:", "attachment; filename=" + FileName + "");
webPage.Response.AddHeader("cache-control", "must-revalidate");
webPage.Response.Write("");
webPage.Response.Write("");
webPage.Response.Write("
webPage.Response.Write("");
webPage.Response.Write("");
webPage.Response.Write("");
webPage.Response.Write("");
webPage.Response.Write("");
webPage.Response.Write("");
webPage.Response.Write("");
webPage.Response.Write("");
webPage.Response.Write("
");
webPage.Response.Write(htmlString);
webPage.Response.Write("
");webPage.Response.Write(htmlString);
webPage.Response.Write("
webPage.Response.Write("");
webPage.Response.Write("");
webPage.Response.Flush();
webPage.Response.End();
}
catch
{
throw;
}
}

Marina EberhardtPosted Nov 12, 2014, 3:32 AM
Hi, try something like the following, first process your HTML string in order to convert it to DOCX with C# and after that you can directly export your DOCX in ASP.NET.
Here is an example:
I hope this helps.Regards,
Marina
White EvalnPosted Oct 19, 2012, 2:49 AM
Document document = new Document(); document.LoadFromFile(@"D:\test.html",FileFormat.Html,XHTMLValidationType.None); document.SaveToFile("test.doc", FileFormat.Doc);
to perform the code, you need to install a .NET ms word component. It works fine in my project, you can give it a try