Exporting a large datagrid to Excel

K

Kevin

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 = "";
ClearControls(newDG);

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

newDG.RenderControl(htmlTW);
}

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

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

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

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top