+-

我想使用“ 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("========================");
}
}
}
}
}
}
但是,我得到了错误
‘Namespace for ‘ZipArchive could not be found’.
我可以确认该应用程序的“目标框架”是.NET Framework 4.5.
谁能指出我正确的方向?
最佳答案
添加对System.IO.Compression和System.IO.Compression.FileSystem的引用.
查看David Anderson的博客:http://www.danderson.me/dotnet/zipfile-class-system-io-compression-filesystem/
希望这可以帮助!
点击查看更多相关文章
转载注明原文:C#列出ZIP文件内容-使用ZipArchive类 - 乐贴网