/// <summary>
/// 增加密码解密加密的压缩文件
/// </summary>
/// <param name="ZipFile"></param>
/// <param name="SavePath"></param>
/// <param name="password"></param>
public static void DecompressFile(string ZipFilePath, string SavePath, string password)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(ZipFilePath));
s.Password = password;
//创建文件夹
Directory.CreateDirectory(SavePath);
try
{
ZipEntry theEntry;
#region 循环读取压缩包里面的文件
while ((theEntry = s.GetNextEntry()) != null)
{
string fileName = Path.GetFileName(theEntry.Name);
if (fileName != String.Empty)
{
#region 在计算文件数目的时候同时创建
//在计算文件数目的时候同时创建
if (Path.GetDirectoryName(theEntry.Name) != "")
{
if (!Directory.Exists(SavePath + "\\" + Path.GetDirectoryName(theEntry.Name)))
{
Directory.CreateDirectory(SavePath + "\\" + Path.GetDirectoryName(theEntry.Name));
}
}
#endregion
//解压文件到指定的目录
FileStream streamWriter = File.Create(SavePath + "\\" + theEntry.Name);
try
{
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
}
catch (ZipException ex)
{
throw new Exception(ex.Message);
}
finally
{
streamWriter.Close();
}
}
}
#endregion
}
catch (Exception zex)
{
throw new Exception(zex.Message);
}
finally
{
s.Close();
}
}