官网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. MYSQL - ORDER BY & LIMIT

    http://stackoverflow.com/questions/4708708/mysql-order-by-limit

  2. DOS永久设置系统环境变量-WMIC

    wmic Windows Management Instrumentation Command-line(Windows管理规范命令行) WMIC扩展WMI(Windows Management In ...

  3. spring 主题使用详解[转]

    在common_include_v2.jsp文件中,spring主题的使用: <link href="${staticPath }/<spring:theme code='sty ...

  4. [转载] select, poll和epoll的区别

    源地址:http://sheepxxyz.blog.163.com/blog/static/61116213201022003513530/ 随着2.6内核对epoll的完全支持,网络上很多的文章和示 ...

  5. JDK环境变量解析

    设置环境变量 在java 中需要设置三个环境变量(1.5之后不用再设置classpath了,但个人强烈建议继续设置以保证向下兼用问题)JDK安装完成之后我们来设置环境变量:右击“我的电脑”,选择“属性 ...

  6. 6 tips for recovering from a flop

    6 tips for recovering from a flop职场没有失败:6招走出工作失误阴影"We all make mistakes, if we're going to lear ...

  7. 阿里巴巴fastJson进行json数据解析

    1.生成JsonObject:将Java bean转换成易于处理和传输的strig的key value形式. 2.解析JsonObject:将收到的字符串转换成JsonObejct这种对象形式,Jso ...

  8. SQLHelper.cs的经典代码-存储过程

    using System; using System.Collections.Generic; using System.Text; using System.Collections; using S ...

  9. Photoshop:不起眼的背景橡皮擦

    背景橡皮擦工具是通过颜色的容差来进行工作的,“+”是定位点,当“+”光标位置在要擦除的位置上的时候,就能擦出比较好的效果. 取样连续:擦除的效果比较连续. 取样一次:不松开鼠标键,也不用担心“+”字中 ...

  10. 构建ASP.NET MVC5+EF6+EasyUI 1.4.3+Unity4.x注入的后台管理系统

    开篇:从50开始系统已经由MVC4+EF5+UNITY2.X+Quartz 2.0+easyui 1.3.4无缝接入 MVC5+EF6+Unity4.x+Quartz 2.3 +easyui 1.4. ...