Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 14, 2009 04:16 AM by Ram Reddy Mekha
Member
10 Points
2 Posts
Nov 14, 2005 03:21 PM|LINK
hi..... I am using below code ....
Using this i am exporting the data from the aspx page to MS Word ..
string ConvtdocFile=System.Convert.ToString(Request.QueryString["ReportName"])+".doc"; Response.Clear(); Response.Charset = ""; Response.Clear(); Response.Charset = ""; Response.ContentType = "application/vnd.ms-word"; Response.AddHeader("Content- Disposition", "inline;filename="+ConvtdocFile); System.IO.StringWriter sw=new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw=new System.Web.UI.HtmlTextWriter(sw); Page.RenderControl(hw); Response.Write(sw.ToString()); //Response.TransmitFile("C:\\Transmit.doc"); Response.WriteFile("C:\\Test.Doc"); Response.End();
Queries:
1. How to save the file in server location using above code? 2. Using above code we can export the data but not images in word. How to export images? Thank's prasanth vaniprasanth@yahoo.com
Contributor
5254 Points
781 Posts
May 14, 2009 03:53 AM|LINK
Hi,
check out these links, it may solve your problem:
http://forums.asp.net/t/1320121.aspx
http://forums.asp.net/p/1017003/1380667.aspx#1380667
http://geekswithblogs.net/vivek/archive/2006/09/26/92316.aspx
Star
9604 Points
1314 Posts
May 14, 2009 04:16 AM|LINK
Try this...
HttpContext.Current.Response.ContentType = "application/msword"; HttpContext.Current.Response.ContentEncoding = System.Text.UnicodeEncoding.UTF8; HttpContext.Current.Response.Charset = "UTF-8"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=Export.doc"); HttpContext.Current.Response.Write("<html>"); HttpContext.Current.Response.Write("<head>"); //Response.Write("<META HTTP-EQUIV=""Content-Type"" CONTENT=""text/html; charset=UTF-8"">"); HttpContext.Current.Response.Write("<meta name=ProgId content=Word.Document>"); //Response.Write("<meta name=Generator content=""Microsoft Word 9"">"); //Response.Write("<meta name=Originator content=""Microsoft Word 9"">");; HttpContext.Current.Response.Write("<style>"); HttpContext.Current.Response.Write("@page Section1 {size:595.45pt 841.7pt; margin:1.0in 1.25in 1.0in 1.25in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}"); HttpContext.Current.Response.Write("div.Section1 {page:Section1;}"); HttpContext.Current.Response.Write("@page Section2 {size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:1.25in 1.0in 1.25in 1.0in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}"); HttpContext.Current.Response.Write("div.Section2 {page:Section2;}"); HttpContext.Current.Response.Write("</style>"); HttpContext.Current.Response.Write("</head>"); HttpContext.Current.Response.Write("<body>"); HttpContext.Current.Response.Write("<div class=Section2>"); //'Section1: Portrait, Section2: Landscape //...... HttpContext.Current.Response.Write("</div>"); HttpContext.Current.Response.Write("</body>"); HttpContext.Current.Response.Write("</html>"); HttpContext.Current.Response.Flush();
vaniprasanth
Member
10 Points
2 Posts
problem with ms word automation using asp.net + c#
Nov 14, 2005 03:21 PM|LINK
hi.....
I am using below code ....
Using this i am exporting the data from the aspx page to MS Word ..
string ConvtdocFile=System.Convert.ToString(Request.QueryString["ReportName"])+".doc";
Response.Clear();
Response.Charset = "";
Response.Clear();
Response.Charset = "";
Response.ContentType = "application/vnd.ms-word";
Response.AddHeader("Content- Disposition", "inline;filename="+ConvtdocFile);
System.IO.StringWriter sw=new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw=new System.Web.UI.HtmlTextWriter(sw);
Page.RenderControl(hw);
Response.Write(sw.ToString());
//Response.TransmitFile("C:\\Transmit.doc");
Response.WriteFile("C:\\Test.Doc");
Response.End();
Queries:
1. How to save the file in server location using above code?
2. Using above code we can export the data but not images in word. How to export images?
Thank's
prasanth
vaniprasanth@yahoo.com
ahsanm.m
Contributor
5254 Points
781 Posts
Re: problem with ms word automation using asp.net + c#
May 14, 2009 03:53 AM|LINK
Hi,
check out these links, it may solve your problem:
http://forums.asp.net/t/1320121.aspx
http://forums.asp.net/p/1017003/1380667.aspx#1380667
http://geekswithblogs.net/vivek/archive/2006/09/26/92316.aspx
DotnetBoss | asp.net boss
Ram Reddy Me...
Star
9604 Points
1314 Posts
Re: problem with ms word automation using asp.net + c#
May 14, 2009 04:16 AM|LINK
Try this...
HttpContext.Current.Response.ContentType = "application/msword"; HttpContext.Current.Response.ContentEncoding = System.Text.UnicodeEncoding.UTF8; HttpContext.Current.Response.Charset = "UTF-8"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=Export.doc"); HttpContext.Current.Response.Write("<html>"); HttpContext.Current.Response.Write("<head>"); //Response.Write("<META HTTP-EQUIV=""Content-Type"" CONTENT=""text/html; charset=UTF-8"">"); HttpContext.Current.Response.Write("<meta name=ProgId content=Word.Document>"); //Response.Write("<meta name=Generator content=""Microsoft Word 9"">"); //Response.Write("<meta name=Originator content=""Microsoft Word 9"">");; HttpContext.Current.Response.Write("<style>"); HttpContext.Current.Response.Write("@page Section1 {size:595.45pt 841.7pt; margin:1.0in 1.25in 1.0in 1.25in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}"); HttpContext.Current.Response.Write("div.Section1 {page:Section1;}"); HttpContext.Current.Response.Write("@page Section2 {size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:1.25in 1.0in 1.25in 1.0in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}"); HttpContext.Current.Response.Write("div.Section2 {page:Section2;}"); HttpContext.Current.Response.Write("</style>"); HttpContext.Current.Response.Write("</head>"); HttpContext.Current.Response.Write("<body>"); HttpContext.Current.Response.Write("<div class=Section2>"); //'Section1: Portrait, Section2: Landscape //...... HttpContext.Current.Response.Write("</div>"); HttpContext.Current.Response.Write("</body>"); HttpContext.Current.Response.Write("</html>"); HttpContext.Current.Response.Flush();Abhiram Reddy Mekha