I tried to convert my dataset into excel and download that excel .I got my required excel file.But System.Threading.ThreadAbortException was raised every excel download. Ho
Looks to be the same question as:
When an ASP.NET System.Web.HttpResponse.End() is called, the current thread is aborted?
So it's by design. You need to add a catch for that exception and gracefully "ignore" it.
I recommend this solution :
Don't use response.End();
Declare this global var : bool isFileDownLoad;
Just after your (response.Write(sw.ToString());) set ==> isFileDownLoad = true;
Override your Render like :
/// AEG : Very important to handle the thread aborted exception
override protected void Render(HtmlTextWriter w)
{
if (!isFileDownLoad) base.Render(w);
}
For me it helped to register a button that calls code behind code as a postback control.
protected void Page_Init(object sender, EventArgs e)
{
ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(btnMyExport);
}
This is not issue but this is by design. The root cause is described in Microsoft Support Page.
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.
The provided Solution is:
For Response.End, call the HttpContext.Current.ApplicationInstance.CompleteRequest method instead of Response.End to bypass the code execution to the Application_EndRequest event
Here is the link: https://support.microsoft.com/en-us/help/312629/prb-threadabortexception-occurs-if-you-use-response-end--response-redi