using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.SharpZipLib.Zip;
using System.IO;
namespace UAS_MES.PublicMethod
{
class ZipHelper
{
///
/// 用于解压缩Zip文件
///
///
///
public static void UnZip(string ZipFilePath, string UnZipPath)
{
if (!File.Exists(ZipFilePath))
{
throw new FileNotFoundException(string.Format("未能找到文件 '{0}' ", ZipFilePath));
}
if (!Directory.Exists(UnZipPath))
{
Directory.CreateDirectory(UnZipPath);
}
using (var s = new ZipInputStream(File.OpenRead(ZipFilePath)))
{
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
if (theEntry.IsDirectory)
{
continue;
}
string directorName = Path.Combine(UnZipPath, Path.GetDirectoryName(theEntry.Name));
string fileName = Path.Combine(directorName, Path.GetFileName(theEntry.Name));
if (!Directory.Exists(directorName))
{
Directory.CreateDirectory(directorName);
}
if (!String.IsNullOrEmpty(fileName))
{
using (FileStream streamWriter = File.Create(fileName))
{
int size = 4096;
byte[] data = new byte[size];
while (size > 0)
{
size = s.Read(data, 0, data.Length);
streamWriter.Write(data, 0, size);
}
}
}
}
}
}
}
}