【发布时间】:2017-07-15 20:48:01
【问题描述】:
我目前正在运行 .net 4.5 版并尝试使用它的“新”压缩功能。我包括System.IO.Compression 并尝试运行以下代码:
using System.IO.Compression;
string startPath = @"c:\example\start";
string zipPath = @"c:\example\result.zip";
string extractPath = @"c:\example\extract";
ZipFile.CreateFromDirectory(startPath, zipPath);
ZipFile.ExtractToDirectory(zipPath, extractPath);
我遇到的问题是The name 'ZipFile does not exist in the current context。如果我已经在使用需要它的东西,我不知道为什么它不存在。
【问题讨论】:
-
@Tinwor 不是重复的,我已经在引用命名空间但仍然出现错误。
-
@JoeScotto 您需要引用 assembly - 最有可能。右键单击项目中的“引用”,单击“添加引用”,然后归档
System.IO.Compression.FileSystem程序集。然后就可以使用命名空间了。 -
您引用了错误的库。这是
System.IO.Compression.FileSystem -
@vcsjones 我没有使用解决方案或项目,我只使用了一个独立的 handler.ashx 文件。
-
骗子有相同的命名空间/程序集问题。将程序集添加到 ashx 的细节是一个单独的问题,可能值得他们自己提出问题。