C#中如何通过ZipFile类操作ZIP文件(压缩、解压)

发布网友 发布时间:2022-04-22 19:58

我来回答

1个回答

热心网友 时间:2023-11-18 00:06

.NET中提供了方法(ZipFile类),用来创建、提取和打开ZIP压缩文档。使用时要引用命名空间:System.IO.Compression。下面的例子给出了通过ZipFile类,如何通过C#压缩ZIP文档、通过C#解压ZIP文档中的内容。using System;using System.IO;using System.IO.Compression;namespace ConsoleApplication{ class Program { static void Main(string[] args) { string startPath = @"c:\example\start"; string zipPath = @"c:\example\result.zip"; string extractPath = @"c:\example\extract"; ZipFile.CreateFromDirectory(startPath, zipPath); //将整个文件夹压缩为ZIP文件 ZipFile.ExtractToDirectory(zipPath, extractPath); //解压ZIP文件到extrat目录中。 } }}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com