Response.End() throws an error when exporting excel in c#

Instead of Response.End() use,

Possible Solution1:
Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();


Note1: Response.End is a bad practice, it aborts the thread to bypass the rest of the operations in the http request lifecycle and it throws an exception

Possible Solution2:
Also try by giving value "true" in Response.End()
 
 
Possible Solution3:
Replace Response.End() with HttpContext.Current.Response.End();

Comments

Popular posts from this blog

Run Powershell script on Remote Computer/Server

Power BI Refresh Issue: unable to convert the value '' from the source data type 'VT_BSTR' to the expected data type 'VT_I8.

SPDActivities - DP.SharePoint.Workflow - Workflow failed to run