Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii,

I have facing problem while download a text file.

Here is my code. I wrote this code in webservice & call this method inside a method.
But It shows thread aborted Error in Response.end().

public void ErrorLog()
   {
       try
       {
           System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
           response.Clear();
           response.ContentType = "application/octet-stream";
           response.AppendHeader("Content-Disposition", "attachment; filename=ErrorFile.txt");
           string path = System.Web.HttpContext.Current.Server.MapPath("~/ErrorFile.txt");
           response.TransmitFile(System.Web.HttpContext.Current.Server.MapPath("~/ErrorFile.txt"));
           response.Flush();
           response.End();
       }
       catch (ThreadAbortException ex)
       {
           Console.Write(ex.ToString());
       }
       catch (Exception ex)
       {
           Console.Write(ex.ToString());

       }
       finally
       {

           //HttpContext.Current.Response.End();
       }
   }


Thanks

Bigyan Sahoo

What I have tried:

Here I use try catch block to find error, but unable to solve them.
Posted
Updated 19-Sep-16 3:21am

1 solution

Use ApplicationInstance.CompleteRequest instead of End.

Correct use of System.Web.HttpResponse.Redirect – Thomas Marquardt's Blog[^]

Also put it outside the catch block.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900