zoukankan      html  css  js  c++  java
  • asp.net for itextsharp 操作pdf

     今天分享下昨天做的一个东西 asp.net 的文件  zip 批量下载,首先你需要去 到http://dotnetzip.codeplex.com这个站点下载zip 的包,在里面找到 Ionic.Zip.dll  引用到你的项目中去
    
          
    
    
    
      /// <summary>
        /// 批量zip下载
        /// </summary>
        /// <param name="Listimg">这里Listimg 是一个数组类型</param>
        public void CreateZip(string Listimg)
        {
            string[] imgs = Listimg.Split(',');
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.BufferOutput = false;
    
    
    
     //网站文件生成一个readme.txt的自述文件(可以不写)
        String readmeText = String.Format("README.TXT" +Environment.NewLine+"网址址:http://aicoffees.com"   );
    
    
    
            HttpContext.Current.Response.ContentType = "application/zip";//以zip 形式输出
            HttpContext.Current.Response.AddHeader("content-disposition", "inline; filename="Photo.zip");//压缩下载的名字
    
            //批量压缩操作
            using (ZipFile zip = new ZipFile())
            {
                for (int i = 0; i < imgs.Length; i++)
                {
    
    
    
    ///在压缩包内添加上面的自述文件,文字编码是系统默认编码形式
    
     zip.AddEntry("Readme.txt", readmeText, Encoding.Default);
    
    
    
    
            zip.Password = "aicoffees.com";//给压缩包设置密码
            zip.Encryption = EncryptionAlgorithm.WinZipAes256;//加密方式
    
    
    
    
    
    
    
                 zip.AddFile(HttpContext.Current.Server.MapPath(imgs[i].ToString()), "");//这里"" 我给的是空就是压缩时不设置文件夹,如果需要取什么名字只需要在“”里面加上就可以了,这里是一个重载方法,如果
    
     zip.AddFile(HttpContext.Current.Server.MapPath(imgs[i].ToString()), "");这样写的话,zip 就会默认把你的image从根目录一直压缩到你的文件所在目录。
    
               
                }
                zip.Save(HttpContext.Current.Response.OutputStream);
    
            }
            HttpContext.Current.Response.Close();
    
        }
    
    
    
    以上是自己的一点小总结,come on
  • 相关阅读:
    Redis配置不当可导致服务器被控制,已有多个网站受到影响 #通用程序安全预警#
    Webstorm10.0.3破解程序及汉化包下载、Webstorm配置入门指南
    用Log Parser Studio分析IIS日志
    使用SQL语句创建和删除约束
    MVC Controller 基类中的Request
    Entity Framework 4.1 绕过 EF 查询映射
    Bash脚本编程学习笔记09:数组
    CentOS 7上的系统管理之:Systemd和systemctl
    Linux是如何启动的?
    CentOS 7上的进程管理
  • 原文地址:https://www.cnblogs.com/yiliuyang/p/4253247.html
Copyright © 2011-2022 走看看