// 添加NuGet包:System.IO.Compression.ZipFile
/**
*┌──────────────────────────────────────────────────────────────┐
*│ 描 述:Zip相关的工具类
*│ 作 者:执笔小白
*│ 版 本:1.0
*│ 创建时间:2022-04-8 15:40:56
*└──────────────────────────────────────────────────────────────┘
*┌──────────────────────────────────────────────────────────────┐
*│ 命名空间: Blog.Core.Common.Helper
*│ 类 名:ZipFileHelper
*└──────────────────────────────────────────────────────────────┘
*/
using System.IO.Compression;
namespace Blog.Core.Common.Helper
{
public class ZipFileHelper
{
/// <summary>
/// 压缩
/// </summary>
/// <param name="sourcePath">指定文件夹</param>
/// <param name="zipFilePath">压缩到zip文件路径</param>
/// <param name="err"></param>
/// <returns></returns>
public static bool CreateZipFile(string sourcePath, string zipFilePath)
{
ZipFile.CreateFromDirectory(sourcePath, zipFilePath);
return true;
}
/// <summary>
/// 解压
/// </summary>
/// <param name="zipFilePath">压缩文件路径</param>
/// <param name="unZipDir">解压文件存放路径。为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹</param>
/// <param name="err">出错信息</param>
/// <returns></returns>
public static bool UnZipFile(string zipFilePath, string unZipDir)
{
ZipFile.ExtractToDirectory(zipFilePath, unZipDir, Encoding.GetEncoding("GBK"), true);
return true;
}
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
作者:꧁执笔小白꧂