title: Possible to download file with code in class library
body: <p>I have a C# Class Library project which inherits a third party solution and then i implement the methods they have provided.</p>
  
  <p>Everything works as expected but one task i am trying to accomplish is to download a file. I have used the below code which i have entered into a class in my project:</p>
  
  <pre><code>string fp = "C:\Complete\Path\File.pdf";
  FileInfo fi= new FileInfo(fp);
  
  System.Web.HttpContext.Current.Response.Clear();
  System.Web.HttpContext.Current.Response.ClearHeaders();
  System.Web.HttpContext.Current.Response.ClearContent();
  System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=test.pdf");
  System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fi.Length.ToString());
  System.Web.HttpContext.Current.Response.ContentType = "application/pdf";
  System.Web.HttpContext.Current.Response.Flush();
  System.Web.HttpContext.Current.Response.TransmitFile(fi.FullName);
  System.Web.HttpContext.Current.Response.End();
  </code></pre>
  
  <ul>
  <li>So the file exists (i can get to it).</li>
  <li>I have stepped through the code and no errors.</li>
  <li>The above code works on a page (Asp .Net page).</li>
  <li>In Chrome the file starts downloading then i receive "Failed- Network error".</li>
  <li>In Edge - page cannot be found.</li>
  </ul>
  
  <p>Is there any other way to trigger a file download when the code resides in a Class library?</p>
  
  <p><strong>Edit 1 (Fiddler)</strong></p>
  
  <p>HTTP/1.1 504 Fiddler - Receive Failure
  Date: Tue, 02 Jan 2018 16:35:40 GMT
  Content-Type: text/html; charset=UTF-8
  Connection: close
  Cache-Control: no-cache, must-revalidate
  Timestamp: 16:35:40.226</p>
  
  <p>[Fiddler] ReadResponse() failed: The server did not return a complete response for this request. Server returned 408 bytes.        </p>
  
  <p><strong>Edit 2</strong></p>
  
  <pre><code>    System.Web.HttpContext.Current.Response.ContentType = "application/pdf";
      System.Web.HttpContext.Current.Response.Flush();
      System.Web.HttpContext.Current.Response.Buffer = false;
      System.Web.HttpContext.Current.Response.TransmitFile(fi.FullName);
      //System.Web.HttpContext.Current.Response.End();
      System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
  </code></pre>