zoukankan      html  css  js  c++  java
  • 压缩文件

    View Code
    using ICSharpCode.SharpZipLib;
    
    using ICSharpCode.SharpZipLib.Checksums;
    
    using ICSharpCode.SharpZipLib.Zip;
    
    using ICSharpCode.SharpZipLib.GZip;
    
    using ICSharpCode.SharpZipLib.BZip2;
    
    
    using ICSharpCode.SharpZipLib.Zip.Compression;
    
    using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
    
     public class MyNameTransfom : ICSharpCode.SharpZipLib.Core.INameTransform
        {
    
            #region INameTransform 成员
    
            public string TransformDirectory(string name)
            {
                return null;
            }
    
            public string TransformFile(string name)
            {
                return Path.GetFileName(name);
            }
    
            #endregion
        }
    
    例子:
    string imgs = Convert.ToString(dr["imgsUrl"]);
                     string name = dr["JingDianName"].ToString();
                     if (imgs != null & imgs != "")
                     {
    
                         string[] sArray = imgs.Split('|');
                         IList<string> listItem = new List<string>();
                       
                         MemoryStream ms = new MemoryStream();
                         byte[] buffer = null;
    
                         using (ZipFile file = ZipFile.Create(ms))
                         {
                             file.BeginUpdate();
                             file.NameTransform = new MyNameTransfom();//通过这个名称格式化器,可以将里面的文件名进行一些处理。默认情况下,会自动根据文件的路径在zip中创建有关的文件夹。
                            
                             foreach (string item in sArray)
                             {
                                 string img_url = "~" + item;
    
                                 file.Add(Server.MapPath(img_url));
                             }
                             file.CommitUpdate();
    
                             buffer = new byte[ms.Length];
                             ms.Position = 0;
                             ms.Read(buffer, 0, buffer.Length);
                         }
    
    
                         Response.AddHeader("content-disposition", "attachment;filename=Images.zip");
                         Response.BinaryWrite(buffer);
                         Response.Flush();
                         Response.End();
                     }
  • 相关阅读:
    Docker的使用
    单元测试框架--Mocha
    Typescript-规范
    Docker Hello World
    node项目的基本构建流程或者打开一个node项目的流程
    node.js安装及初用
    windows系统安装MongoDB
    微信小程序实现滚动视频自动播放(未优化)
    js判断一个字符串中出现次数最多的字符及次数
    vue相关知识点及面试
  • 原文地址:https://www.cnblogs.com/chai1338/p/2693436.html
Copyright © 2011-2022 走看看