Invalid zip file after creating it with System.IO.Compression : <p>I'm trying to create a zip file that contains one or more files.<br/>
I'm using the .NET framework 4.5 and more specifically System.IO.Compression namespace.<br/>
The objective is to allow a user to download a zip file through a ASP.NET MVC application.<br/>
The zip file is being generated and sent to the client but when I try to open it by doing double click on it I get the following error:<br/>
Windows cannot open the folder.
The compressed (zipped) folder ... is invalid.<br/>
Here's my code:</p>

<pre><code>[HttpGet]
public FileResult Download()
{
    var fileOne = CreateFile(VegieType.POTATO);
    var fileTwo = CreateFile(VegieType.ONION);
    var fileThree = CreateFile(VegieType.CARROT);

    IEnumerable&lt;FileContentResult&gt; files = new List&lt;FileContentResult&gt;() { fileOne, fileTwo, fileThree };
    var zip = CreateZip(files);

    return zip;
}

private FileContentResult CreateFile(VegieType vType)
{
    string fileName = string.Empty;
    string fileContent = string.Empty;

    switch (vType)
    {
        case VegieType.BATATA:
            fileName = "batata.csv";
            fileContent = "THIS,IS,A,POTATO";
            break;
        case VegieType.CEBOLA:
            fileName = "cebola.csv";
            fileContent = "THIS,IS,AN,ONION";
            break;
        case VegieType.CENOURA:
            fileName = "cenoura.csv";
            fileContent = "THIS,IS,A,CARROT";
            break;
        default:
            break;
    }

    var fileBytes = Encoding.GetEncoding(1252).GetBytes(fileContent);
    return File(fileBytes, MediaTypeNames.Application.Octet, fileName);
}

private FileResult CreateZip(IEnumerable&lt;FileContentResult&gt; files)
{
    byte[] retVal = null;

    if (files.Any())
    {
        using (MemoryStream zipStream = new MemoryStream())
        {
            using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create, false))
            {
                foreach (var f in files)
                {
                    var entry = archive.CreateEntry(f.FileDownloadName, CompressionLevel.Fastest);
                    using (var entryStream = entry.Open())
                    {
                        entryStream.Write(f.FileContents, 0, f.FileContents.Length);
                        entryStream.Close();
                    }
                }

                zipStream.Position = 0;
                retVal = zipStream.ToArray();
            }
        }
    }

    return File(retVal, MediaTypeNames.Application.Zip, "horta.zip");
}
</code></pre>

<p>Can anyone please shed some light on why is windows saying that my zip file is invalid when I double click on it.<br/>
A final consideration, I can open it using 7-Zip.</p>
