1

I am trying to download multiple files in zip format. I've followed every single things that I've found online, but still failed.

Here is my code.

public FileResult DownloadMultipleFiles(IEnumerable<string> fileName)
    {
        //var newfile = @"C:\MyProject\Content\Reports\pdf3.pdf";
        using (var ms = new MemoryStream())
        using (var zip = new ZipArchive(ms, ZipArchiveMode.Create, true))
        {
            foreach (var file in fileName)
            {               
                zip.CreateEntryFromFile(newfile, Path.GetFileName(file));
            }

            return File(ms.ToArray(), "application/zip");
        }
  }

The 'newfile' variable is the sample data of whats inside the 'filename' variable.

The code runs with no error, at first glance but no file is downloaded. If I put a breakpoint after 'zip.CreateEntryFromFile' method, inside, i can see its throwing below exception.

zip.Entries threw an exception of type 'System.NotSupportedException'

Can anyone point me to the exact issue here?

sicKo
  • 1,241
  • 1
  • 12
  • 35
  • Not sure if it is exactly the same error, but the exception type is the same as this possible related question [Writing to ZipArchive using the HttpContext OutputStream](https://stackoverflow.com/a/21513194/2265446) – Cleptus Aug 09 '21 at 17:31
  • what are the exception details? – Steeeve Aug 09 '21 at 18:10

0 Answers0