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

I have an SSIS project with me, I can work as is. But, when I try to edit it, an error message appears

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

without editing, it works great

Error code:

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?

+8
c # zipfile ssis
source share
4 answers

Make sure you are using .Net 4.5. Link to dll compression. Here is the path: C: \ Program Files (x86) \ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.5 \ System.IO.Compression.FileSystem.dll link in the class "use System.IO.Compression.FileSystem" If the class is inherited from another class, do not forget to refer to the parent class. (This is what I have to do to compile it)

+13
source share

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

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

For more information about how to add a link to your project in Visual Studio, see How-To:

Add or remove links using the link manager.

+1
source share

For update only:

In .Net version 4.6.1

Adding a reference to System.IO.Compression.FileSystem and using System.IO.Compression enough.

using System.IO.Compression.FileSystem gives below error.

Original error

0
source share

I found that the ZipFile class ZipFile not only cooperate using System.IO.Compression , it would ask to see the Link to System.IO.Compression.FileSystem .

If you are using Visual Basic, adding a link is pretty simple. In the solution explorer, one of the tabs in the project is called Links. Right-click and select Add Link. Scroll a bit next to System.IO.Compression.FileSystem . Once you click OK, you don’t even have to explicitly reference System.IO.Compression.FileSystem in your code!

Good luck (:

0
source share

All Articles