1. 大家可以到http://www.icsharpcode.net/opensource/sharpziplib/ 下载SharpZiplib的最新版本,支持Zip, GZip, BZip2 和Tar格式,本作者的项目代码如下

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 ICSharpCode.SharpZipLib.Zip;//来自项目icsharpcode-SharpZipLib-e012155生成的ICSharpCode.SharpZipLib.dll

namespace TestZIP
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
try
{
using (FolderBrowserDialog dlg = new FolderBrowserDialog())
{
//dlg.CheckFileExists = true;
//dlg.CheckPathExists = true;
if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
if (dlg.SelectedPath != null)
{
FastZip fz = new FastZip();
fz.CreateZip("123.zip", dlg.SelectedPath, true, "");
MessageBox.Show("压缩完成!", "信息提示:", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
//throw;
}
}

private void button2_Click(object sender, EventArgs e)
{
try
{
using (OpenFileDialog dlg = new OpenFileDialog())
{
//dlg.CheckFileExists = true;
//dlg.CheckPathExists = true;
if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
if (dlg.FileName != null)
{
FastZip fz = new FastZip();
fz.ExtractZip(dlg.FileName, Application.StartupPath + "\\新建文件夹", "");
//fz.CreateZip("123.zip", dlg.SelectedPath, true, "");
MessageBox.Show("解压完成!", "信息提示:", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
//throw;
}
}
}
}

项目zip压缩解压缩  项目icsharpcode-SharpZipLib-e012155-LMLPHP

05-11 17:51