ASP.NET下载所有的文件邮编 [英] ASP.NET Download All Files as Zip

查看:149
本文介绍了ASP.NET下载所有的文件邮编的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹中,有数以百计的MP3文件在它我的Web服务器上。我想提供的选项为用户从网页上下载每个MP3的压缩文档的目录。

I have a folder on my web server that has hundreds of mp3 files in it. I would like to provide the option for a user to download a zipped archive of every mp3 in the directory from a web page.

我想COM preSS编程仅在需要时的文件。因为zip文件将是相当大的,我想,我需要将zip文件发送到响应流中的因为它是被压缩,出于性能的考虑。

I want to compress the files programmatically only when needed. Because the zip file will be quite large, I am thinking that I will need to send the zip file to the response stream as it is being zipped, for performance reasons.

这可能吗?我该怎么办呢?

Is this possible? How can I do it?

推荐答案

下面是code我用用DotNetZip做到这一点 - 工作得非常好。很显然,您需要提供变量ou​​tputFileName,夹folderName和includeSubFolders。

Here is code I use to do this with DotNetZip - works very well. Obviously you will need to provide the variables for outputFileName, folderName, and includeSubFolders.

response.ContentType = "application/zip";
response.AddHeader("content-disposition", "attachment; filename=" + outputFileName);
using (ZipFile zipfile = new ZipFile()) {
  zipfile.AddSelectedFiles("*.*", folderName, includeSubFolders);
  zipfile.Save(response.OutputStream);
}

这篇关于ASP.NET下载所有的文件邮编的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆