By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 1,211 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

error "Thread Being Aborted" while downloading file

P: n/a
Hi following is the code which sends file to the browser means user can
download file,
but the code generates error message Thread Being Aborted., will any
one put their thoughts

protected void SendFileToBrowser(string strpath)
{
try
{
FileInfo objFileInfo = new FileInfo(strpath);
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;
filename=" + objFileInfo.Name);
Response.AddHeader("Content-Length",
objFileInfo.Length.ToString());
Response.WriteFile(objFileInfo.FullName);
Response.End();
}
catch (Exception ex)
{
Response.Write("");
}
}

Thanks
----
Hitendra Patel

Feb 15 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
DWS
try taking out the response.write("") out of the catch block.

"hi********@gmail.com" wrote:
Hi following is the code which sends file to the browser means user can
download file,
but the code generates error message Thread Being Aborted., will any
one put their thoughts

protected void SendFileToBrowser(string strpath)
{
try
{
FileInfo objFileInfo = new FileInfo(strpath);
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;
filename=" + objFileInfo.Name);
Response.AddHeader("Content-Length",
objFileInfo.Length.ToString());
Response.WriteFile(objFileInfo.FullName);
Response.End();
}
catch (Exception ex)
{
Response.Write("");
}
}

Thanks
----
Hitendra Patel

Feb 15 '06 #2

P: n/a
> Hi following is the code which sends file to the browser means user can
download file,
but the code generates error message Thread Being Aborted., will any
one put their thoughts

protected void SendFileToBrowser(string strpath)
{
try
{
FileInfo objFileInfo = new FileInfo(strpath);
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;
filename=" + objFileInfo.Name);
Response.AddHeader("Content-Length",
objFileInfo.Length.ToString());
Response.WriteFile(objFileInfo.FullName);
Response.End();
}
catch (Exception ex)
{
Response.Write("");
}
}

Thanks
----
Hitendra Patel


You will get a "tread aborted" exception when you do a
Response.Redirect from within a try block. Maybe this also happens for
a Response.End.
Try moving that outside of the try/catch.

Hans Kesting
Feb 15 '06 #3

P: n/a
Thanks DWS

Feb 15 '06 #4

P: n/a
Thanks Hans Kesting

Feb 15 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.