posts - 609,  comments - 13,  views - 64万
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5
参考:https://blog.csdn.net/zhaotianff/article/details/141156035
复制代码
using System.IO.Compression;
namespace XCG.Commons
{
    public class ZipUtil
    {
        /// <summary>
        /// 压缩zip
        /// </summary>
        /// <param name="inputFolder">要压缩的目录</param>
        /// <param name="destinationZipPath">压缩后zip存放地址</param>
        public static void CreateZip(string inputFolder, string destinationZipPath)
        {
            if (Directory.Exists(inputFolder))
            {
                ZipFile.CreateFromDirectory(inputFolder, destinationZipPath);
            }
        }

        /// <summary>
        /// 解压zip
        /// </summary>
        /// <param name="zipFilePath">zip压缩包地址</param>
        /// <param name="extractPath">解压到此目录</param>
        public static void ExtractZip(string zipFilePath, string extractPath)
        {
            if (File.Exists(zipFilePath))
            {
                ZipFile.ExtractToDirectory(zipFilePath, extractPath);
            }
        }
    }
}
复制代码

 测试代码

复制代码
 [HttpGet]
 public void GenRarZip()
 {
     //获取项目路径
     var webRootPath = this._env.ContentRootPath;
     var fileDir = $"UploadFile\\123\\";
     var dirPath = Path.Combine(webRootPath, fileDir);
     //压缩包存放地址
     var tarDir = $"ZipFile\\123.zip";
     var tarPath = Path.Combine(webRootPath, tarDir);
     ZipUtil.CreateZip(dirPath, tarPath);
 }
复制代码

 

posted on   邢帅杰  阅读(21)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
历史上的今天:
2022-10-14 .net maui拨打电话
2015-10-14 sql标量值函数,将汉字转化为拼音,无音标
点击右上角即可分享
微信分享提示