c# - 压缩和解压缩文件

标签 c# unzip

我正在处理一个需要解压缩文件并将其存储在特定文件夹中的项目。但问题是,我不知道该怎么做。这是我第一次从事此类项目。

我使用的是 visual studio 2010。我不会使用任何第三方应用程序。

谁能建议我该怎么做?

我试过这段代码,但无法识别 ZIPFILE。它上面有一条红线。

using System;
using System.IO;
using System.IO.Compression;

namespace UnzipFile
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void btnZip_Click(object sender, RoutedEventArgs e)
    {
        string startPath = @"c:\example\start";
        string zipPath = @"c:\example\result.zip";
        string extractPath = @"c:\example\extract";

        ZipFile.CreateFromDirectory(startPath, zipPath);

        ZipFile.ExtractToDirectory(zipPath, extractPath);
    }
}

enter image description here

最佳答案

Microsoft 现在已通过使用 ZipFile 将存档包含在 .NET 框架中命名空间。

为了让它很短,压缩一个目录,你可以使用下面的代码:

ZipFile.CreateFromDirectory(sourceFolder, outputFile);

关于c# - 压缩和解压缩文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23906185/

相关文章:

PHP - 解压/打开返回整数

c# - 为什么 EF 尝试使用单个或多个 SaveChanges() 插入实例两次?

C# - 单例模式

c# - 如何在不刷新整个站点的情况下更新表

java - 如何以编程方式搜索某个 JAR 中的文件?

c# - Shell32.dll 引用导致问题

c# - 当我尝试在 MVVM WPF 中使用命令修改对象时,为什么在 View 模型中出现空错误?

c# - 使用 ASP.NET Webforms 的 Ajax 发布

download - 为什么我不能让 st_read 从压缩文件中打开 shapefile? (如果保存在本地 Onedrive 文件夹中但未在 R 中解压缩,则会读取 map )

ruby-on-rails - 如何使用 ruby​​zip 库获取压缩文件的内容?