我不能在名称空间"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"这个名称在当前上下文中不存在
我怎么解决呢?
我是Visual Studio编程的新手.
我最近将.Net 4.0升级到4.5以便在System.IO.Compression下使用ZipFile类,但是在安装完成后,Visual Studio(我使用2012)仍然无法将ZipFile识别为类名.
我确保.Net 4.5出现在控制面板程序列表中,而我的C#解决方案将.Net Framework 4设置为目标框架.
有人可以帮我解决这个问题吗?