I'm downloading an Excel file in ASP.Net that works in Firefox and IE, but not Chrome.
A link on a calling page opens this page in a new window which generates a spreadsheet, downloads it, then closes the window.
In my hex editor, the file downloaded via Chrome includes HTML markup from the aspx page which produces an error trying to open it in Excel.
Firefox and IE download it without the HTML.
I thought Response.Close() was ending the output. How do I tell Chrome that there is nothing else to download?
A link on a calling page opens this page in a new window which generates a spreadsheet, downloads it, then closes the window.
Code:
protected void Page_Load(object sender, EventArgs e)
{
handleExport();
}
void handleExport()
{
// ...
// Code to produce spreadsheet is here...
// ...
// Write the Excel spreadsheet from the MemoryStream and send it to the browser
string saveAsFileName = sFileName + ".xlsx";
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", saveAsFileName));
workbook.Write(Response.OutputStream);
Response.Flush();
Response.Close();
Page.ClientScript.RegisterOnSubmitStatement(typeof(Page), "closePage", "window.onunload = CloseWindow();");
}
In my hex editor, the file downloaded via Chrome includes HTML markup from the aspx page which produces an error trying to open it in Excel.
Firefox and IE download it without the HTML.
I thought Response.Close() was ending the output. How do I tell Chrome that there is nothing else to download?