I know its very old question but may be helpful for others...
The Response.End method ends the page execution and shifts the execution to the Application_EndRequest event in the application's event pipeline. The line of code that follows Response.End is not executed.
Instead of
Response.End(), use
HttpContext.Current.ApplicationInstance.CompleteRequest()
string excelXml = GetExcelXml(dsInput, filename);
response.Clear();
response.AppendHeader("Content-Type", "application/vnd.ms-excel");
response.AppendHeader("Content-disposition", "attachment;
filename=" + filename);
response.Write(excelXml);
response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
Source:
Microsoft official website[
^]