解压ZIP文件
/// <summary>
/// 解压ZIP文件
/// </summary>
/// <param name="strZipPath">待解压的ZIP文件</param>
/// <param name="strUnZipPath">解压的目录</param>
/// <param name="overWrite">是否覆盖</param>
/// <returns>成功:true/失败:false</returns>
public static bool Decompression(string strZipPath, string strUnZipPath, bool overWrite)
{
try
{
ReadOptions options = new ReadOptions();
options.Encoding = Encoding.Default;//设置编码,解决解压文件时中文乱码
using (ZipFile zip = ZipFile.Read(strZipPath, options))
{
foreach (ZipEntry entry in zip)
{
if (string.IsNullOrEmpty(strUnZipPath))
{
strUnZipPath = strZipPath.Split('.').First();
}
if (overWrite)
{
entry.Extract(strUnZipPath, ExtractExistingFileAction.OverwriteSilently);//解压文件,如果已存在就覆盖
}
else
{
entry.Extract(strUnZipPath, ExtractExistingFileAction.DoNotOverwrite);//解压文件,如果已存在不覆盖
}
}
return true;
}
}
catch (Exception)
{
return false;
}
}

以上动图由“图斗罗”提供
这篇c#打包文件解压缩的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持ASPKU。
注:相关教程知识阅读请移步到c#教程频道。










