string strDocbody = ""; strDocbody="<html " + "xmlns:o='urn:schemas-microsoft-com:office:office' " + "xmlns:w='urn:schemas-microsoft-com:office:word'" + "xmlns='http://www.w3.org/TR/REC-html40'>" + "<head><title></title>"; strDocbody+= "<!--[if gte mso 9]>" + "<xml>" + "<w:WordDocument>" + "<w:View>Print</w:View>" + "<w:Zoom>90</w:Zoom>" + "<w:DoNotOptimizeForBrowser/>" + "</w:WordDocument>" + "</xml>" + "<![endif]-->"; strDocbody+="<style>" + "<!-- /* Style Definitions */" + "p.MsoFooter, li.MsoFooter, div.MsoFooter" + "{margin:0in;" + "margin-bottom:.0001pt;" + "mso-pagination:widow-orphan;" + "tab-stops:center 3.0in right 6.0in;" + "font-size:12.0pt;}" + "p.MsoHeader, li.MsoHeader, div.MsoHeader" + "{margin:0in;" + "margin-bottom:.0001pt;" + "mso-pagination:widow-orphan;" + "tab-stops:center 3.0in right 6.0in;" + "font-size:12.0pt;}"; strDocbody+="@page Section1" + " {size:8.5in 11.0in; " + " margin:1.5in 0.6in 2in 0.6in ; " + " mso-header: h1;" + " mso-header-margin:.5in; " + " mso-footer: f1;" + " mso-footer-margin:.5in; mso-paper-source:0;}" + " div.Section1" + " {page:Section1;" + "font-size:10.0pt;font-family:Times New Roman;mso-fareast-font-family:Times New Roman" + " }" + "-->" + "</style></head>"; strDocbody+="<body lang=EN-US style='tab-interval:.5in'>" + "<div class=Section1>"; //body System.IO.StringWriter sw1 = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter oHtmlTextWriter1 = new System.Web.UI.HtmlTextWriter(sw1); divbody.RenderControl(oHtmlTextWriter1); strDocbody = strDocbody + oHtmlTextWriter1.InnerWriter.ToString() + "</div>"; //header System.IO.StringWriter sw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(sw); divhead.RenderControl(oHtmlTextWriter); strDocbody += "<div style='mso-element:header' id=h1>" + "<p class=MsoHeader>" + oHtmlTextWriter.InnerWriter.ToString() + "</p></div>"; //strDocbody += oHtmlTextWriter.InnerWriter.ToString(); // //footer System.IO.StringWriter sw2 = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter oHtmlTextWriter2 = new System.Web.UI.HtmlTextWriter(sw2); divfooter.RenderControl(oHtmlTextWriter2); strDocbody += "<div style='mso-element:footer' id=f1>" + " <p class=MsoFooter>" + oHtmlTextWriter2.InnerWriter.ToString() + "</p></div>"; strDocbody+="</body></html>"; Response.AddHeader("Content-Type", "application/msword"); //filename specify the name of word document of your choice Response.AddHeader("Content-disposition", "attachment; filename=myWordDoc.doc"); //Response.Charset = ""; Response.Write(strDocbody);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)