-
"unable to read file" error when opening excel generated by asp.net
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
Similar Threads
-
By eranfox in forum VB Classic
Replies: 5
Last Post: 08-09-2007, 07:18 AM
-
By zali in forum VB Classic
Replies: 1
Last Post: 03-06-2006, 04:15 AM
-
By jase_dukerider in forum C++
Replies: 2
Last Post: 04-14-2005, 07:48 PM
-
Replies: 8
Last Post: 01-09-2003, 09:42 PM
-
By Magnus Olsson in forum ASP.NET
Replies: 0
Last Post: 12-21-2002, 08:21 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks