Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The name 'zipfile' does not exist in the current context

Tags:

c#

zipfile

ssis

I have an SSIS project that I can run as is, but when I try to edit it, I get an error:

The name 'zipfile' does not exist in the current context

Without editing, it works fine.

The code that's producing the error:

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;
}

How can I solve this?

like image 440
vignesh Avatar asked Apr 21 '15 10:04

vignesh


Video Answer


2 Answers

Make sure you are using .NET version 4.5. Reference the Compression DLL - here is the path:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.IO.Compression.FileSystem.dll

Reference it in the class by adding using System.IO.Compression.FileSystem. If the class is inherited from another class, make sure to reference it in the parent class too. (This is what I have to do to make it compile)

like image 186
Puneet Vedi Avatar answered Sep 20 '22 15:09

Puneet Vedi


To use the ZipFile class, you must add a reference to the System.IO.Compression.FileSystem assembly in your project; otherwise, you'll get the following error message when trying to compile:

The name 'ZipFile' does not exist in the current context.

For more information on how to add a reference to your project in Visual Studio, see How to: Add or remove references by using the Reference Manager.

like image 22
Robert Peter Bronstein Avatar answered Sep 20 '22 15:09

Robert Peter Bronstein