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?