Export to excel - Issue on Windows Server 2008 IIS7
I am trying to export to repeter/Gridview in excel, this is working fine in my local machine and windows server 2003, however when I deployed on Windows server 2008 its not working properly
. here is my code
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
string attachment = "attachment; filename=myReport.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
rpt.RenderControl(htw);
Response.Write(sw.ToString());
Response.Flush();
Response.End();
Server Details : Windows Server 2008 and IIS7
In mozilla all the page contents are exported to e开发者_StackOverflow中文版xcel with an error but in IE & Chrome, empty excel file is exported without data.
You are writing a string to the response. I would expect this file type to be binary and therefore you should be using Response.BinaryWrite(). What is actually coming from rpt.RenderControl(htw)? I suspect, that you should change your content type to text/csv, which excel will still handle.
精彩评论