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;
}
}


White Evaln26 pointsPosted Oct 18, 2012, 10:49 PM EDT
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
Marina Eberhardt24 pointsPosted Nov 11, 2014, 10:32 PM EST
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:
public void ServeAsDocx(System.Web.UI.Page webPage, string fileName) { string htmlString = GetHtmlForPage(); DocumentModel document; var options = LoadOptions.HtmlDefault; using (var htmlStream = new MemoryStream(options.Encoding.GetBytes(htmlString))) document = DocumentModel.Load(htmlStream, options); document.Save(webPage.Response, fileName, SaveOptions.DocxDefault); }Regards,
Marina