title: Downloading large files asp.net mvc 3?
body: <p>I have a large pdf file (upto 2 GBs) on  a database server which I want to send to client for download. Also, I have size limitations on my web server and cannot store complete file on it, after requesting from data server. I am using asp.net mvc 3. Any suggestions on how can I accomplish this? Also I want it to be asynchronous since I don't want to block the user from clicking other buttons on the web page.</p>
  
  <p>I have tried using this code.</p>
  
  <pre><code>//code for getting data from data server into inputstream
  HttpContext.Response.ContentType = "application/pdf";
  HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
  HttpContext.Response.BufferOutput = false;     
  try
  {
     using (Stream inputStream = resp.GetResponseStream())
     {
       byte[] buffer = new byte[SegmentSize];
       int bytesRead;
       while ((bytesRead = inputStream.Read(buffer, 0, SegmentSize)) &gt; 0)
       {
          HttpContext.Response.OutputStream.Write(buffer, 0, bytesRead);
          HttpContext.Response.Flush();
       }
      }
   }
  catch (Exception ex)
  {
     //some code
  }
  </code></pre>
  
  <p>This downloads the file but then I don't know how to make it asynchronous? Also is there any other way to do the download that would be asynchronous too?</p>