Reputation: 30303
In web application, i am using code, to download the documnet which is uploaded, which is written in item command event of datalist, but it s giving error like "Thread was being aborted" can you help me to solve this, thank you. My code is as fallows.
protected void dtlstMagazine_ItemCommand(object source, DataListCommandEventArgs e)
{
try
{
objItMagBe.TitleId = Convert.ToInt32(e.CommandArgument);
dts = new DataSet();
dts = objItMagBL.GetMagzineByTitleID(objItMagBe);
GetPopularMagazine();
string Myfile = "../xxxx/DataFiles/" + dts.Tables[0].Rows[0]["Files"].ToString();
if (File.Exists(Server.MapPath(Myfile)) == true)
{
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Myfile);
Response.TransmitFile(Server.MapPath(Myfile));
Response.End();
Response.Flush();
}
}
catch
{
}
}
Upvotes: 1
Views: 9637
Reputation: 29849
The issue is that you're calling Response.End()
before Response.Flush()
. Swap the order of those statements and the issue will go away.
Upvotes: 0
Reputation: 19175
Your Response.End() is most likely what is causing that. It is because it is telling ASP.NET that the request is over.
What is the stack trace from the Exception, where does .NET think the exception is being thrown from?
Upvotes: 1
Reputation: 3546
You sure that doesn't happen in other code not shown ? usually you get that with when you redirect while inside a try-catch
Upvotes: 0
Reputation: 6149
It seems that the file is big so the IIS is killing the thread, you should change this in the web.config:
<httpRuntime
maxRequestLength="1048576"
executionTimeout="3600"
/>
maxRequestLength is in bytes
executionTimeout is in seconds
Upvotes: 2