Hi,

I am exporting content of datagrid to ms excel. My problem is that everything works great when I test this in development and QA environments but in the production I am getting error "unable to read file" while opening the excel. This error happens when there is no row in the datagrid. I tested this scenario in dev and QA and I don;t see any problem but in Prod I am getting the error. Below is the code which I am using to export the datagrid content to excel.

this.OrderHistoryDataGrid.DataSource = dv;
this.OrderHistoryDataGrid.DataBind();
// redirect the output to an excel spreadsheet
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
Response.AddHeader( "Content-Disposition","attachment; filename=TradeWeb_Retail_" + title + DateTime.Now.ToString("yyyy_MM_dd_HH_mm") + ".xls" );
this.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter tw = new System.Web.UI.HtmlTextWriter(sw);
this.OrderHistoryDataGrid.RenderControl(tw);
Response.Write(this.spnExcelStyle.InnerHtml);Response.Write(sw.ToString());Response.Flush( );

Please help.

Thanks,

Amit