0

According to this answer, we could use something like:

public FileResult Download()
{
    byte[] fileBytes = System.IO.File.ReadAllBytes(@"c:\folder\myfile.ext");
    string fileName = "myfile.ext";
    return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
}

..to download a file.

In my case, I have to download multiple files.
For example,

foreach(int _id in idArray)
{
    byte[] file = //..... generate file using _id
    MemoryStream ms = new MemoryStream();
    ms.Write(file, 0, file.Length);
    ms.Position = 0;

    return File(ms, "application/pdf", myFileName);
}

But this code downloads only the first file.
According to this answer, we could generate a zip achieved for multiple files.
But in my scenario, I have to download the files separately. How should I change my code to download multiple files?

Steven Sann
  • 478
  • 1
  • 7
  • 27

0 Answers0