How to compress multiple files in zip file
<p>I'm trying to compress two text files to a zip file. This is how my public method looks like:</p>

<pre><code>public ActionResult Index()
{

    byte[] file1 = System.IO.File.ReadAllBytes(@"C:\file1.txt");
    byte[] file2 = System.IO.File.ReadAllBytes(@"C:\file2.txt");
    Dictionary&lt;string, byte[]&gt; fileList = new Dictionary&lt;string, byte[]&gt;();
    fileList.Add("file1.txt", file1);
    fileList.Add("file2.txt", file2);
    CompressToZip("zip.zip", fileList);

    return View();
}
</code></pre>

<p>This is how my compress method looks like:</p>

<pre><code>private void CompressToZip(string fileName, Dictionary&lt;string, byte[]&gt; fileList)
{
    using (var memoryStream = new MemoryStream())
    {
        foreach (var file in fileList)
        {
            using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
            {
                var demoFile = archive.CreateEntry(file.Key);

                using (var entryStream = demoFile.Open())
                using (var b = new BinaryWriter(entryStream))
                {
                    b.Write(file.Value);
                }
            }
        }

        using (var fileStream = new FileStream(fileName, FileMode.Create))
        {
            memoryStream.Seek(0, SeekOrigin.Begin);
            memoryStream.CopyTo(fileStream);
        }
    }

}
</code></pre>

<p>In this approach, the zip folder is perfectly created. However the issue is I'm getting only one file inside the zip folder (Just the second file will be created inside the zip folder).
There are no errors found. </p>

<blockquote>
  <p>Question: How to compress both text files into the zip folder?</p>
</blockquote>

<p>Thank you in advanced!</p>