We might come across a situation where we need to download multiple files and since a response cannot contain more than one file result; the best way to do is to zip all the content and download the zip file.
Here's how we do it:
We need Ionic.Zip.Dll
We need
using System.IO;
using Ionic.Zip;byte[] zipContent = null;
using (var zip = new ZipFile())
{
zip.AddFile(Server.MapPath("~/Ionic.Zip1.dll"));
zip.AddFile(Server.MapPath("~/Ionic.Zip2.dll"));
//assign all zip content to content
using (var ms = new MemoryStream())
{
zip.Save(ms);
zipContent = ms.ToArray();
}
}
Response.AppendHeader("Content-Disposition", string.Concat("inline; filename=\"", "download.zip", "\""));
return File(zipContent, "zip");