需要引用 DLL-ICSharpCode.SharpZipLib 下载地址
http://download.youkuaiyun.com/download/cleopard/8304539
using System;
using System.Collections.Generic;
using System.Text;
using ICSharpCode.SharpZipLib.Zip;
using System.IO;
using ICSharpCode.SharpZipLib.Checksums;
namespace Help
{
/// <summary>
/// 压缩通用帮助类
/// </summary>
public class ZipHelper
{
/// <summary>
/// 解压功能(解压压缩文件到指定目录)
/// </summary>
/// <param name="FileToUpZip">待解压的文件</param>
/// <param name="ZipedFolder">指定解压目标目录</param>
public static void UnZip(string FileToUpZip, string ZipedFolder)
{
if (!File.Exists(FileToUpZip))
{
return;
}
if (!Directory.Exists(ZipedFolder))
{
Directory.CreateDirectory(ZipedFolder);
}
ZipInputStream sInput = new ZipInputStream(File.OpenRead(FileToUpZip));
try
{
ZipEntry theEntry;
while ((theEntry = sInput.GetNextEntry()) != null)
{
if (theEntry.Name != String.Empty)
{
string fileName = Path.Combine(ZipedFolder, theEntry.Name);
//判断文件路径是否是文件夹
if (fileName.EndsWith("/") || fileName.EndsWith("\\"))
{
Directory.CreateDirectory(fileName);
continue;
}
string newDir = Path.GetDirectoryName(fileName);
if (!Directory.Exists(newDir))
{
Directory.CreateDirectory(newDir);
}
FileStream streamWriter = File.Create(fileName);
try
{
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = sIn