Exporting a large datagrid to Excel



I'm using a bit of code I wrote awhile ago to render datagrids to Excel
spreadsheets through the browser. The code works great until the number
of rows in the datagrid gets large (approx. 5000), then the user is
prompted for their login credentials a few times then finally they get
a 401 error. The solution for other people who have encountered this
problem is to upgrade their Office 2K to a more current SP. In my case
all my users are running Office 2003 SP1. Has anybody run across this
problem and found a solution?

For reference, here's the method I wrote to render the datagrid

public static System.Web.HttpResponse
Export_DataGrid(System.Web.HttpResponse Response,
ArrayList dataGrids,
string FileName)
StringBuilder SB = new StringBuilder();
foreach(DataGrid dg in dataGrids)
//DataGrid newDG = dataGrids;
DataGrid newDG = dg;
newDG.EnableViewState = false;
newDG.CssClass = "";

StringWriter SW = new StringWriter(SB);
HtmlTextWriter htmlTW = new HtmlTextWriter(SW);


//System.Web.HttpResponse Response = new HttpResponse(htmlTW);

Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
Response.AppendHeader("Content-Disposition", "attachment; filename="
+ FileName + ".xls;");

return Response;


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question