Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 名称';zipfile';在当前上下文中不存在_C#_Ssis_Zipfile - Fatal编程技术网

C# 名称';zipfile';在当前上下文中不存在

C# 名称';zipfile';在当前上下文中不存在,c#,ssis,zipfile,C#,Ssis,Zipfile,我有一个可以按原样运行的SSIS项目,但当我尝试编辑它时,会出现错误: 当前上下文中不存在名称“zipfile” 无需编辑,效果良好 产生错误的代码: public void Main() { // TODO: Add your code here string moduleName = Dts.Variables["User::ModuleName"].Value.ToString(); string s = Dts.Variables["User::ZipFileLo

我有一个可以按原样运行的SSIS项目,但当我尝试编辑它时,会出现错误:

当前上下文中不存在名称“zipfile”

无需编辑,效果良好

产生错误的代码:

public void Main()
{
    // TODO: Add your code here
    string moduleName = Dts.Variables["User::ModuleName"].Value.ToString();
    string s = Dts.Variables["User::ZipFileLocation"].Value.ToString().TrimEnd('\\') + "\\" + moduleName + "\\" + moduleName + "_" + DateTime.Now.ToString("ddMMyyyy");

    // TODO: Add your code here
    string startPath = s;
    string zipPath = s + ".zip";

    try
    {
        File.Delete(zipPath);
        ZipFile.CreateFromDirectory(startPath, zipPath);
    }
    catch (Exception e)
    {
    }

    Dts.TaskResult = (int)ScriptResults.Success;
}

如何解决此问题?

请确保您使用的是.NET 4.5版。参考压缩DLL-以下是路径:

C:\ProgramFiles(x86)\Reference Assembly\Microsoft\Framework\.NETFramework\v4.5\System.IO.Compression.FileSystem.dll


通过使用System.IO.Compression.FileSystem添加
,在类中引用它。如果该类是从另一个类继承的,请确保在父类中也引用它。(这就是我要编译它所必须做的)

要使用
ZipFile
类,必须在项目中添加对
System.IO.Compression.FileSystem
程序集的引用;否则,您将在尝试编译时收到以下错误消息:

当前上下文中不存在名称“ZipFile”


有关如何在Visual Studio中添加对项目的引用的详细信息,请参阅

仅用于更新:-

使用.Net 4.6.1版本

添加对
System.IO.Compression.FileSystem的引用
使用System.IO.Compression
就足够了

使用System.IO.Compression.FileSystem
给出以下错误


我发现
ZipFile
类不能仅使用
System.IO.Compression
进行协作,它要求查看
System.IO.Compression.FileSystem
引用

如果您使用的是VisualBasic,那么添加引用相当容易。在解决方案资源管理器中,项目下的一个选项卡称为引用。在那里单击鼠标右键,然后选择“添加引用”。向下滚动一点,选中
System.IO.Compression.FileSystem
旁边的复选框。单击“确定”后,您甚至不需要在代码中显式引用
System.IO.Compression.FileSystem


祝你好运(:

您可能只引用了System.IO.Compression,奇怪的是您需要引用System.IO.Compression.FileSystemtoo@NilsO这是我的问题。不确定为什么我们必须为此添加一个单独的引用,但在我这边解决了这个问题。@Chad这是因为Zipfile类位于System.IO.Compression.a文件系统中在System.IO.Compression命名空间中进行组装。是的,我看到了相同的情况。您不需要DLL,只需使用下面的代码即可