官网http://www.icsharpcode.net/

支持文件和字符压缩。

创建全新的压缩包

第一步,创建压缩包

using ICSharpCode.SharpZipLib.Zip;
ZipOutputStream zipOutputStream = new ZipOutputStream(File.Create(strZipPath));
参数:strZipPath,提供压缩后的文件包全路径,即地址和文件名。如,D:\tmp\01.rar
第二步,向压缩包中添加压缩包的文件名
ICSharpCode.SharpZipLib.Zip.ZipEntry entry = new ICSharpCode.SharpZipLib.Zip.ZipEntry(name);
entry.DateTime = System.DateTime.Now;
zipOutputStream.PutNextEntry(entry);
如01.rar压缩包中包含A.txt,B.txt,C.txt三个文件,那么参数name则对应为A.txt,B.txt,C.txt。
第三步,向压缩包中的entry写入文件
System.IO.FileStream fs = System.IO.File.OpenRead(strFile);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, , buffer.Length);
zipOutputStream.Write(buffer, , buffer.Length);
fs.Close();
fs.Dispose();

参数:strFile,待压缩的文件全路径。

第二步、第三步,可以循环,向压缩包中添加更多的文件。

向已有的压缩包中添加新文件

ICSharpCode.SharpZipLib.Zip.ZipFile z = new ICSharpCode.SharpZipLib.Zip.ZipFile();

唯一区别是使用ZipFile代替ZipOutputStream,打开已有的压缩文件。

每天学习,进步一点点。

利用ICSharpCode.SharpZipLib.Zip进行文件压缩的更多相关文章

  1. C# 利用ICSharpCode.SharpZipLib实现在线加密压缩和解密解压缩 C# 文件压缩加解密

    C# 利用ICSharpCode.SharpZipLib实现在线加密压缩和解密解压缩   这里我们选用ICSharpCode.SharpZipLib这个类库来实现我们的需求. 下载地址:http:// ...

  2. C# 下利用ICSharpCode.SharpZipLib.dll实现文件/目录压缩、解压缩

    ICSharpCode.SharpZipLib.dll下载地址 1.压缩某个指定文件夹下日志,将日志压缩到CompressionDirectory文件夹中,并清除原来未压缩日志. #region 压缩 ...

  3. C# 利用ICSharpCode.SharpZipLib实现在线加密压缩和解密解压缩

    这里我们选用ICSharpCode.SharpZipLib这个类库来实现我们的需求. 下载地址:http://icsharpcode.github.io/SharpZipLib/ 1.单个或多个文件加 ...

  4. c# ICSharpCode.SharpZipLib.Zip实现文件的压缩

    首先了解ZipOutPutStream和ZipEntry对象 ZipOutPutStream对象 如果要完成一个文件或文件夹的压缩,则要使用ZipOutputStream类.ZipOutputStre ...

  5. 使用ICSharpCode.SharpZipLib.Zip实现压缩与解压缩

    使用开源类库ICSharpCode.SharpZipLib.Zip可以实现压缩与解压缩功能,源代码和DLL可以从http://www.icsharpcode.net/OpenSource/SharpZ ...

  6. 基于ICSharpCode.SharpZipLib.Zip的压缩解压缩

    原文:基于ICSharpCode.SharpZipLib.Zip的压缩解压缩 今天记压缩解压缩的使用,是基于开源项目ICSharpCode.SharpZipLib.Zip的使用. 一.压缩: /// ...

  7. C#使用ICSharpCode.SharpZipLib.dll进行文件的压缩与解压

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  8. 利用ICSharpCode.SharpZipLib进行压缩

    #ZipLib is a Zip, GZip, Tar and BZip2 library written entirely in C# for the .NET platform. It is im ...

  9. 使用NPOI读取Excel报错ICSharpCode.SharpZipLib.Zip.ZipException:Wrong Local header signature

    写了一个小程序利用NPOI来读取Excel,弹出这样的报错: ICSharpCode.SharpZipLib.Zip.ZipException:Wrong Local header signature ...

随机推荐

  1. HDU 2602 Bone Collector (简单01背包)

    Bone Collector http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , i ...

  2. C# static方法-使用迭代器循环遍历文件中的额行

    //封装的方法 //读取文件的值,放入集合中 public static IEnumerable<string> ReadLines(string fileName) { using (T ...

  3. Codeigniter 利用加密Key(密钥)的对象注入漏洞

    http://drops.wooyun.org/papers/1449 原文链接:http://www.mehmetince.net/codeigniter-object-injection-vuln ...

  4. ****RESTful API 设计最佳实践(APP后端API设计参考典范)

    http://blog.jobbole.com/41233/ 背景 目前互联网上充斥着大量的关于RESTful API(为方便,下文中“RESTful API ”简写为“API”)如何设计的文章,然而 ...

  5. C之算法

       1° 选择排序算法    核心思路如下图: 以字符串排序进行说明 #include <stdio.h> #include <string.h> #define SIZE ...

  6. Maven的配置文件pom.xml

    Maven的配置文件pom.xml 简介: 什么是POM? POM是项目对象模型(Project Object Model)的简称,它是Maven项目中的文件,使用XML表示,名称叫做pom.xml. ...

  7. Badboy录制

    摘要 Badboy是一个强大的工具,被设计用于测试和开发复杂的动态应用.Badboy功能丰富(包括一个捕获/重播接口,强大的压力测试支持,详细的报告.图形)使得测试和开发更加容易. Badboy是用来 ...

  8. lintcode:数字组合I

    数字组合I 给出一组候选数字(C)和目标数字(T),找到C中所有的组合,使找出的数字和为T.C中的数字可以无限制重复被选取. 例如,给出候选数组[2,3,6,7]和目标数字7,所求的解为: [7], ...

  9. servlet学习笔记一

    Servlet一.基本概念 我们的程序根据是否需要访问网络,可分为网络程序和非网络程序.而 网络程序又分为B/S结构和C/S结构. 什么是C/S?即客户端(Client)/服务器(Server)模式. ...

  10. html 页面表单如果是disabled,则不能提交到服务器端,request.getParameter得到的将为null

    html 页面表单如果是disabled,则不能提交到服务器端,request.getParameter得到的将为null 解决方法:使用hidden 利用javascript赋值,传递到后台