简体   繁体   English

如何使用asp和C#下载多个文件

[英]How to download multiple files using asp and C#

I'm pretty new at this, so bear with me.我对此很陌生,所以请耐心等待。 Here's my code.这是我的代码。 It only downloads one file even though multiple are selected.即使选择了多个文件,它也只会下​​载一个文件。

foreach(String fileName in fileNameList)
{
    FileInfo updateFile = new FileInfo("C:/inetpub/wwwroot/w4/DanyaWebReports/Data/" + fileName);
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("content-disposition", "attachment;filename=\"" + Path.GetFileName(updateFile.FullName) + "\"");
    Response.AddHeader("content-length", updateFile.Length.ToString());
    Response.TransmitFile(updateFile.FullName);
    Response.Flush();
}

that is not the way to go, you can either zip all selected files server side and download only the zip file or you can try to use client side code to open multiple download windows, but in that case I think some browsers could potentially block the popups with their popup blockers.这不是要走的路,您可以压缩所有选定的文件服务器端并仅下载 zip 文件,或者您可以尝试使用客户端代码打开多个下载窗口,但在这种情况下,我认为某些浏览器可能会阻止带有弹出窗口阻止程序的弹出窗口。

something like, you create a page called download.aspx ( or even just an http handler ) then you call it multiple times via JavaScript:类似于,您创建了一个名为 download.aspx(甚至只是一个 http 处理程序)的页面,然后您通过 JavaScript 多次调用它:

window.open("download.aspx?id=id of file1");
window.open("download.aspx?id=id of file2");

check here for some ideas you can further elaborate: ASP.NET Download Multiple files在此处查看您可以进一步阐述的一些想法: ASP.NET 下载多个文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM