多选打包下载
using Ionic.Zip;
/////////////////在对多文件打包中用到了 DotNetZip 的方法来实现对多文件压缩打包。需要到http://dotnetzip.codeplex.com/处下载该文件,然后引用Ionic.Zip即可
/////////////////在对多文件打包中用到了 DotNetZip 的方法来实现对多文件压缩打包。需要到http://dotnetzip.codeplex.com/处下载该文件,然后引用Ionic.Zip即可
public void PackDown()
{
string fileUrls = "/UploadFiles/CallRecord/201412/20141203172322375.mp3|/UploadFiles/CallRecord/201412/20141203172304379.mp3|";
if (fileUrls.Length > 0)
fileUrls = fileUrls.Remove(fileUrls.Length - 1);
string[] Directories = System.Text.RegularExpressions.Regex.Split(fileUrls, "\\|");
Response.Clear();
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=DotNetZip.zip");
using (ZipFile zip = new ZipFile(System.Text.Encoding.Default))//解决中文乱码问题
{
for (int i = 0; i < Directories.Length; i++)
{
try
{
string fileUrl = HttpContext.Current.Server.MapPath("~" + Directories[i]);
zip.AddFile(fileUrl, "");
}
catch (Exception ex)
{
}
}
zip.Save(Context.Response.OutputStream);
}
Response.End();
}