error "Thread Being Aborted" while downloading file

  • Thread starter Thread starter hitendra15
  • Start date Start date
H

hitendra15

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
 
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

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
 
Back
Top