C#列出ZIP文件内容-使用ZipArchive类

C#列出ZIP文件内容-使用ZipArchive类,c#,zip,.net,C#,Zip,.net,我想使用“ZipArchive”类获取ZIP文件中的内容列表 我正在使用MSDN中的一个示例: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Win

我想使用“ZipArchive”类获取ZIP文件中的内容列表

我正在使用MSDN中的一个示例:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Compression;
using System.IO.Compression.dll;

namespace Zip_Extractor
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (FileStream zipToOpen = new FileStream(@"c:\users\exampleuser\release.zip", FileMode.Open))
            {
                using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
                {
                    ZipArchiveEntry readmeEntry = archive.CreateEntry("Readme.txt");
                    using (StreamWriter writer = new StreamWriter(readmeEntry.Open()))
                    {
                            writer.WriteLine("Information about this package.");
                            writer.WriteLine("========================");
                    }
                }
            }
        }
    }
}
然而,我得到了错误

'找不到'ZipArchive'的命名空间'

我可以确认应用程序的“目标框架”是.NET framework 4.5


谁能给我指出正确的方向吗

添加对
System.IO.Compression
System.IO.Compression.FileSystem
的引用

查看David Anderson的博客:


希望这有帮助

右键单击引用,添加对框架程序集System.IO.Compression和System.IO.Compression.FileSystem的引用。包括使用System.IO.Compression;并确保您使用的是.NET Framework 4.5。

我在这方面做得晚了,但它可能会帮助某些人

添加对其他答案中提到的文件的引用:

  • 系统IO压缩
  • System.IO.Compression.FileSystem
添加这些属性后,它可能无法工作,因此进入它们的属性并将每个属性的“copy local”设置标记为“True”


这把戏是为我做的。:)

我遇到了同样的问题,并在
Assemblies->Framework:

中查找了这些名称空间 只需添加名称空间:
System.IO.Compression&System.IO.Compression.FileSystem

以下是屏幕截图,便于理解/理解:


是否添加了
System.IO.Compression.dll
作为参考?添加此项会导致错误“名称空间System.IO.Compression中不存在类型或名称空间名称'dll'。我想这可能是.NET版本的问题。我已经添加了这些参考资料。但是,我得到一个错误,名称空间System.IO.Compression中不存在类型或名称空间名称“FileSystem”。有什么想法吗?当我在应用程序选项卡上选择Project>{Project Name}属性时,“目标框架”是.NET framework 4.5。我正在使用Visual Studio Pro 2012。请尝试为该应用程序设置完全信任。使用“这是一个完全信任的应用程序”没有乐趣我仍然收到错误1命名空间“System.IO.Compression”中不存在类型或命名空间名称“dll”(是否缺少程序集引用?),您可以尝试改用DotNetZip。它与ZipFile类具有相同的功能。