我不能在名称空间"System.IO.Compression"中使用"Zipfile"类我的代码是:
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, CompressionLevel.Fastest,true);
ZipFile.ExtractToDirectory(zipPath, extractPath);
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误是:
"zipfile"这个名称在当前上下文中不存在
我怎么解决呢?
Mar*_*ell 201
您需要向程序集"System.IO.Compression.FileSystem.dll"添加一个dll引用 - 并确保您使用的是.NET 4.5(因为它在早期的框架中不存在).
有关信息,您可以从MSDN中找到程序集和.NET版本
Wil*_*ger 32
对于那些在.NET中是绿色程序员的人来说,要像MarcGravell所说的那样添加DLL引用,请按照以下步骤操作:
在Visual C#中添加引用
从MSDN文章,如何:使用添加引用对话框添加或删除引用.
Joh*_*ner 18
如果您无法升级到4.5,则可以使用外部包.其中一个是来自DotNetZipLib的Ionic.Zip.dll.
using Ionic.Zip;
Run Code Online (Sandbox Code Playgroud)
你可以在这里免费下载.http://dotnetzip.codeplex.com/