首页 > 其他 > 详细

多选打包下载

时间:2016-01-07 16:43:30      阅读:220      评论:0      收藏:0      [点我收藏+]
using 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();
    }

多选打包下载

原文:http://www.cnblogs.com/deep-blue/p/5109958.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!