title: ThreadAbortException (WebClient using DownloadFile to grab file from server)
body: <p>Referencing my <a href="https://stackoverflow.com/questions/2444888/webclient-using-download-file-to-grab-file-from-server-handling-exceptions">Earlier Question</a>, regarding downloading a file from a server and handling exceptions properly. I am positive that I had this solved, then in classic programming fashion, returned days later to frustratingly find it broken :-(</p>
  
  <hr>
  
  <p><strong>Updated code:</strong></p>
  
  <pre><code>private static void GoGetIt(HttpContext context)
      {
          var directoryInfoOfWhereTheDirectoryFullOfFilesShouldBe = new FileInfo(......);
                  var name = SomeBasicLogicToDecideName();
  
              //if (!directoryInfoOfWhereTheDirectoryFullOfFilesShouldBe.RefreshExists())
              //{
              //  throw new Exception(string.Format("Could not find {0}.", name));
              //}
  
              var tempDirectory = ""; //Omitted - creates temporary directory
  
              try
              {
                  directoryInfoOfWhereTheDirectoryFullOfFilesShouldBe.CopyAll(tempDirectory);
                  var response = context.Response;
                  response.ContentType = "binary/octet-stream";
                  response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}.zip", name));
                  ZipHelper.ZipDirectoryToStream(tempDirectory, response.OutputStream);
                  response.End();
              }
              catch (Exception ex)
              {
                  Debug.WriteLine(ex.ToString());
                  context.Response.StatusCode = 404;
              }
              finally
              {
                  tempDirectory.DeleteWithPrejudice();
              }
          }
  </code></pre>
  
  <hr>
  
  <p>This was working fine, and returning the zip, otherwise if the file didn't exist returning 404. Then on the client side I could handle this:</p>
  
  <pre><code>public bool Download()
  {   
   try
                  {
                      using (var client = new WebClient())
                      {
                          client.DownloadFile(name, tempFilePath);
                      }
  
                  }
                  catch (Exception)
                  {
                      fileExists = false;
                  }
  return fileExists;
      }
  </code></pre>
  
  <hr>
  
  <p>But the problem now is two things.</p>
  
  <p>1) I get System.Threading.ThreadAbortException: Thread was being aborted in the server side try-catch block. Usually this was just a file not found exception. I have no idea what or why that new exception is throwing?</p>
  
  <p>2) Now that a different exception is throwing on the server side instead of the file not found, it would seem I can't use this set up for the application, because back on client side, any exception is assumed to be filenotfound.</p>
  
  <p>Any help, especially info on why this ThreadAbortException is throwing!?!? greatly appreciated. Cheers</p>