title: HttpContext.Current.Response write file after download manager starts
body: <p>I'm trying to create a ZIP file on the fly which might contain a few thousands of pictures. </p>
  
  <p>
      public static void CompressAndSendFiles(List files)
      {
          HttpContext.Current.Response.ClearContent();</p>
  
  <pre><code>    // LINE1: Add the file name and attachment, which will force the open/cance/save dialog to show, to the header
      HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=\"Jpeg Package " 
                                              + DateTime.Now.ToString("MM-dd-yyyy hh-mm-ss") + ".zip\"");
  
      // Add the file size into the response header
      //HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
  
      // Set the ContentType
      HttpContext.Current.Response.ContentType = ReturnHttpContentType("download.zip");
  
      ZipOutputStream oZipStream = 
                     new ZipOutputStream(HttpContext.Current.Response.OutputStream);
  
      try
      {
          foreach (string file in files)
          {
  
  
              FileInfo fInfo = new FileInfo(file);
              ZipEntry oZipEntry = new ZipEntry(fInfo.Name);
              oZipStream.PutNextEntry(oZipEntry);
              byte[] buffer = File.ReadAllBytes(file);
              oZipStream.Write(buffer, 0, buffer.Length);
  
              //oZipStream.Flush();
          }
      }
      catch (Exception ex)
      {
          throw ex;
      }
      finally
      {
          oZipStream.Finish();
          oZipStream.Close();
          oZipStream.Dispose();
  
       }
       HttpContext.Current.Response.OutputStream.Flush();
       HttpContext.Current.Response.End();
  }
  </code></pre>
  
  <p>Everything is fine, unless when number of files get big. </p>
  
  <p>My question:
  Is there a way to initiate the download (let the download manager on client side popup), and then start writing on the stream?</p>
  
  <p>I monitored w3wp.exe (IIS) process, and it seems that the data is being written on memory instead of Stream. When w3wp.exe memory usage riches a certain number, it releases the memory and nothing happens (no download).</p>
  
  <p>Thank you in advance.</p>