【发布时间】:2013-04-17 20:32:21
【问题描述】:
我想使用“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.dll作为参考? -
添加这个会给我错误“命名空间 System.IO.Compression 中不存在类型或命名空间名称 'dll'”。我认为这可能是 .NET 版本的问题。