下载地址:http://dotnetzip.codeplex.com/
解压后找到\\DotNetZipLib-DevKit-v1.9\zip-v1.9\Release下的Ionic.Zip.dll文件拷贝到C盘下
接着打开Visual Studio Command Prompt (2010),然后定位到C盘根目录,依次输入gacutil -i Ionic.Zip.dll 和regasm Ionic.Zip.dll ,然后拷贝C盘下的这个Ionic.Zip.dll到您的应用程序中,添加引用即可!代码例子如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ionic.Zip;
namespace WindowsFormsZIP
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 压缩带中文的文件名.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void button1_Click(object sender, EventArgs e)
{
using (ZipFile zip = new ZipFile("苏志.zip",Encoding.Default))
{
zip.AddFile("数据库文档.doc");
zip.Save();
}
}
/// <summary>
/// 用密码加密ZIP文件.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void button2_Click(object sender, EventArgs e)
{
using (ZipFile zip = new ZipFile())
{
zip.Password = "123456!";
zip.AddFile("WPF 4 Unleashed.pdf");
zip.Save("WPF 4 Unleashed.zip");
}
}
/// <summary>
/// 压缩文件夹
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void button3_Click(object sender, EventArgs e)
{
using (ZipFile zip = new ZipFile())
{
zip.AddDirectory(@"E:\suzhi");
zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G");
zip.Save("test.zip");
}
}
/// <summary>
/// 抽取ZIP中的文件到指定的文件夹.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void button4_Click(object sender, EventArgs e)
{
using (ZipFile zip = ZipFile.Read("test.zip"))
{
foreach (ZipEntry z in zip)
{
z.Extract(@"F:\kk");
}
}
}
}
}