Here's the export piece of my code:
private void ExportGridView()
{
// Exports the data in the GridView to Excel
// First, fill the datagrid with the results of the session variable
DataTable gridDataSource = (DataTable)Session["SSRegisterSplit"];
DataGrid dgGrid = new DataGrid();
dgGrid.DataSource = gridDataSource;
dgGrid.DataBind();
// Exports the data in the GridView to Excel
string attachment = "attachment; filename=Claim_Details_" + LPI_ID + ".xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
dgGrid.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
When it exports, it shows up in my footer automatically with an option to Open or Save.
If I choose "Open", Excel launches and then I get an error box:
The file you are trying to open, 'Claim_Details_1586.xls' is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?
If I choose 'Yes', it opens the file but not all the records are in it.
Any ideas on what's happening/how to fix it?
EDIT:
Putting a break point in the function, I noticed that when it gets to Response.End();
it throws the error:
Thread Was being Aborted.