title: OutOfMemory exception when trying to download multiple files as a Zip file using Ionic.Zip dll
body: <p>This is my working code that I used to download multiple files as a zip file using <code>Ionic.Zip</code> dll. File contents is stored in a SQL database. This program works if I try to download 1-2 files at a time, but throws an <code>OutOfMemory</code> exception if I try to download multiple files as some of the files may very large.</p>
  
  <p>Exception occurs when it's trying to write in to <code>outputStream</code>.</p>
  
  <p>How can I improve this code to download multiple files or is there a better way to download multiple files one by one rather than zipping them to a one large file?</p>
  
  <p>Code: </p>
  
  <pre><code>public ActionResult DownloadMultipleFiles()
  {
      string connectionString = "MY DB CONNECTIOBN STRING";
  
      List&lt;Document&gt; documents = new List&lt;Document&gt;();
      var query = "MY LIST OF FILES - FILE METADA DATA LIKE FILEID, FILENAME";
      documents = query.Query&lt;Document&gt;(connectionString1).ToList();
  
      List&lt;Document&gt; DOCS = documents.GetRange(0, 50); // 50 FILES
  
      Response.Clear();     
      var outputStream = new MemoryStream();
  
      using (var zip = new ZipFile())
      {
          foreach (var doc in DOCS)
          {
              Stream stream = new MemoryStream();
              byte[] content = GetFileContent(doc.FileContentId); // This method returns file content
              stream.Write(content, 0, content.Length);
  
              zip.UseZip64WhenSaving = Zip64Option.AsNecessary // edited
  
              zip.AddEntry(doc.FileName, content);
          }
  
          zip.Save(outputStream);
      }
  
      return File(outputStream, "application/zip", "allFiles.zip");
  }
  </code></pre>