日韩欧美人妻无码精品白浆,www.大香蕉久久网,狠狠的日狠狠的操,日本好好热在线观看

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

C#壓縮解壓文件處理方案

admin
2025年6月3日 10:17 本文熱度 809

1、通過 System.IO.Compression 命名空間中新增的ZipArchive、ZipFile等類實現(xiàn)。

不需要安裝第三方的組件包,微軟官方的實現(xiàn),推薦使用

//壓縮
System.IO.Compression.ZipFile.CreateFromDirectory(@"C:\Users\Pride\Pictures\test\123", @"C:\Users\Pride\Pictures\test\123.zip"); 
//解壓
System.IO.Compression.ZipFile.ExtractToDirectory(@"C:\Users\Pride\Pictures\test\123.zip", @"C:\Users\Pride\Pictures\test\1234"); 

2、第三方類庫(DotNetZip的使用)

  • SharpZipLib[1]

  • DotNetZip[2]

SharpZipLib的簡單使用

DotNetZip的簡單使用

壓縮文件

using (ZipFile zip = new ZipFile())
{
  zip.AddFile("c:\\photos\\personal\\7440-N49th.png");
  zip.AddFile("c:\\Desktop\\2005_Annual_Report.pdf");
  zip.AddFile("ReadMe.txt");

  zip.Save("Archive.zip");
}

更新文件,無需解壓

using (ZipFile zip = ZipFile.Read("ExistingArchive.zip"))
{
  // 1. remove an entry, given the name
  zip.RemoveEntry("README.txt");

  // 2. Update an existing entry, with content from the filesystem
  zip.UpdateItem("Portfolio.doc");

  // 3. modify the filename of an existing entry
  // (rename it and move it to a sub directory)
  ZipEntry e = zip["Table1.jpg"];
  e.FileName ="images/Figure1.jpg";

  // 4. insert or modify the comment on the zip archive
  zip.Comment ="This zip archive was updated" + System.DateTime.ToString("G");

  // 5. finally, save the modified archive
  zip.Save();
}

提取文件

using (ZipFile zip = ZipFile.Read("ExistingZipFile.zip"))
{
  foreach (ZipEntry e in zip)
  {
    e.Extract(TargetDirectory, true);  // true => overwrite existing files
  }
}

3、原生 System.IO.Compression 實現(xiàn) zip 的壓縮與解壓

不需要安裝第三方的組件包,微軟官方的實現(xiàn),需要添加命名空間using System.IO.Compression;

將指定目錄壓縮為Zip文件

/// <summary>
/// 將指定目錄壓縮為Zip文件
/// </summary>
/// <param name="folderPath">文件夾地址 D:/1/ </param>
/// <param name="zipPath">zip地址 D:/1.zip </param>
public static void CompressDirectoryZip(string folderPath, string zipPath)
{
    DirectoryInfo directoryInfo = new(zipPath);
 
    if (directoryInfo.Parent != null)
    {
        directoryInfo = directoryInfo.Parent;
    }
 
    if (!directoryInfo.Exists)
    {
        directoryInfo.Create();
    }
 
    ZipFile.CreateFromDirectory(folderPath, zipPath, CompressionLevel.Optimal, false);
}

將指定文件壓縮為Zip文件

/// <summary>
/// 將指定文件壓縮為Zip文件
/// </summary>
/// <param name="filePath">文件地址 D:/1.txt </param>
/// <param name="zipPath">zip地址 D:/1.zip </param>
public static void CompressFileZip(string filePath, string zipPath)
{
 
    FileInfo fileInfo = new FileInfo(filePath);
    string dirPath = fileInfo.DirectoryName?.Replace("\\", "/") + "/";
    string tempPath = dirPath + Guid.NewGuid() + "_temp/";
    if (!Directory.Exists(tempPath))
    {
        Directory.CreateDirectory(tempPath);
    }
    fileInfo.CopyTo(tempPath + fileInfo.Name);
    CompressDirectoryZip(tempPath, zipPath);
    DirectoryInfo directory = new(path);
    if (directory.Exists)
    {
        //將文件夾屬性設(shè)置為普通,如:只讀文件夾設(shè)置為普通
        directory.Attributes = FileAttributes.Normal;
 
        directory.Delete(true);
    }
}

解壓Zip文件到指定目錄(壓縮單個文件的邏輯其實就是先將我們要壓縮的文件復(fù)制到一個臨時目錄,然后對臨時目錄執(zhí)行了壓縮動作,壓縮完成之后又刪除了臨時目錄)

/// <summary>
/// 解壓Zip文件到指定目錄
/// </summary>
/// <param name="zipPath">zip地址 D:/1.zip</param>
/// <param name="folderPath">文件夾地址 D:/1/</param>
public static void DecompressZip(string zipPath, string folderPath)
{
    DirectoryInfo directoryInfo = new(folderPath);
 
    if (!directoryInfo.Exists)
    {
        directoryInfo.Create();
    }
 
    ZipFile.ExtractToDirectory(zipPath, folderPath);
}
復(fù)制

資料參考

  • C# 壓縮或解壓_WenyueQ°的博客-CSDN博客_c# 解壓[3]

  • .NET中zip的壓縮和解壓 - Asharp - 博客園[4]

  • 使用C#和System.IO.Packaging以編程方式從Zip存檔中提取文件 | 碼農(nóng)家園[5]

  • C# 使用原生 System.IO.Compression 實現(xiàn) zip 的壓縮與解壓_大哥手下留情的博客-CSDN博客[6]

引用鏈接

[1] SharpZipLib: http://www.icsharpcode.net/opensource/sharpziplib/
[2] DotNetZip: http://dotnetzip.codeplex.com/
[3] C# 壓縮或解壓_WenyueQ°的博客-CSDN博客_c# 解壓: https://blog.csdn.net/u014325666/article/details/126298552
[4] .NET中zip的壓縮和解壓 - Asharp - 博客園: https://www.cnblogs.com/zhaozhan/archive/2012/05/28/2520701.html
[5] 使用C#和System.IO.Packaging以編程方式從Zip存檔中提取文件 | 碼農(nóng)家園: https://www.codenong.com/507751/
[6] C# 使用原生 System.IO.Compression 實現(xiàn) zip 的壓縮與解壓_大哥手下留情的博客-CSDN博客: https://blog.csdn.net/dageliuqing/article/details/127177937


該文章在 2025/6/3 15:22:34 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運作、調(diào)度、堆場、車隊、財務(wù)費用、相關(guān)報表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點,圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務(wù)都免費,不限功能、不限時間、不限用戶的免費OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved

国产无码3p| 婷婷的八十区按摩| 国产一区二区三区加勒比av| 后入日韩三区| 黄色一级自拍| 大香蕉网大香蕉中码在线| 免费高清视频一区二区| 亚洲第一色 婷婷| 丰满丰满的熟女一区二区二一| 7777凹凸视频国产精品影视| 国产传媒自拍电影| 麻豆文化传媒精品一区观看| 国产久久麻豆电影| 日日日日爽日日日日日日日日日爽| 免费不卡青青草| av不卡手机免费在线观看| 婷婷一区二区三区四区成| 丁香婷婷深爱网| 亚洲欧美精品一区二区小黄书| 熟女午夜免费视频| 一区二区三区四区电影网| 99精品欧美一区二区三区视频| 内射中出极品日韩在线| 人妻夜夜爽一区| 午夜亚洲日本中文字幕不卡| 亚洲欧美日韩图片视频| 亚洲日韩成人小说| 探花少妇导航| 少妇AV偷拍| 国产久热综合欧美| 国产家庭乱日本中文一区| 北条麻妃肛交一区二区三区| 蜜桃中文av| 中文字幕有码不卡好看经典| 久久久探花嫖妓66XX一区| 99久久兔费国产精品| 国产激情久久久久熟女老人| 久久99九九| 欧美1级A黄片| 成人色呦| 91伊人97|