How to download multiple files? Getting “Server cannot clear headers after HTTP headers have been sent.”

前端 未结 1 460
一生所求
一生所求 2021-01-16 18:17

I have an MVC application that shows a list of files for download. The user selects the files with a checkbox and these are generated as PDF\"s on the server side using the

相关标签:
1条回答
  • 2021-01-16 19:00

    You can zip all selected files and send it across. There is library available for same on codeplex called DotNetZip This is how you can zip it.

    var outputStream = new MemoryStream();
    
    using (var zip = new ZipFile())
    {
        zip.AddFile("path to file one");
        zip.AddFile("path to file two");
        zip.AddFile("path to file three");
        zip.AddFile("path to file four");
        zip.Save(outputStream);
    }
    
    outputStream.Position = 0;
    return File(outputStream, "application/zip","zip file name.zip");
    
    0 讨论(0)
提交回复
热议问题