I'm developing an ASP.NET MVC 5 application, and I wrote a code that allows me to download files stored in a SQL Server database as varbinary
, I'm able to download a single file with this:
public JsonResult PrepareSingleFile(int [] IdArray)
{
ImageContext _contexte = new ImageContext();
var response =_contexte.contents.Find(IdArray.FirstOrDefault());
//byte[] FileData =
Encoding.UTF8.GetBytes(response.image.ToString());
byte[] FileData = response.image;
Session["data"] = FileData;
Session["filename"] = response.FileName;
return Json(response.FileName);
}
public FileResult DownloadSingleFile()
{
var fname = Session["filename"];
var data = (byte[]) Session["data"];
//return File(data,"application/pdf");
return File(data,System.Net.Mime.MediaTypeNames.Application.Pdf, fname.ToString()+".pdf");
}
But now I want to download multiple files, so I'm getting the data of each file as a byte array and putting those byte arrays inside a List<byte[]>
and I want to download those files as a zip file, so how can I do that?
I tried this:
File(data,"the Mime Type", "file name.extension")
But it doesn't work when data
is a List<byte[]>
.