3

I would like to obtain a list of contents in a ZIP file using the 'ZipArchive' class.

I am using an example from MSDN:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO.Compression; using System.IO.Compression.dll; namespace Zip_Extractor { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { using (FileStream zipToOpen = new FileStream(@"c:\users\exampleuser\release.zip", FileMode.Open)) { using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update)) { ZipArchiveEntry readmeEntry = archive.CreateEntry("Readme.txt"); using (StreamWriter writer = new StreamWriter(readmeEntry.Open())) { writer.WriteLine("Information about this package."); writer.WriteLine("========================"); } } } } } } 

However, I get the error

'Namespace for 'ZipArchive could not be found'.

I can confirm the 'Target framework' for the application is .NET Framework 4.5.

Can anyone point me in the right direction?

2
  • Did you add System.IO.Compression.dll as a reference? Commented Apr 24, 2013 at 10:22
  • Adding this gives me the error "the type or namespace name 'dll' does not exist in the namespace System.IO.Compression". I think this may be a .NET version issue. Commented Apr 24, 2013 at 10:37

4 Answers 4

3

Add references to System.IO.Compression and System.IO.Compression.FileSystem.

Check David Anderson's blog: http://www.danderson.me/dotnet/zipfile-class-system-io-compression-filesystem/

Hope this Helps!

Sign up to request clarification or add additional context in comments.

6 Comments

I have added these references. However I am getting the error the type or namespace name 'FileSystem' does not exist in the namespace System.IO.Compression. Any ideas?
When I select Project>{Project Name} Properties on the Application tab - the 'Target framework' is .NET Framework 4.5. I am using Visual Studio Pro 2012.
Try to set Full trust for the application.
No joy with 'This is a full trust application'. - I still get Error 1 The type or namespace name 'dll' does not exist in the namespace 'System.IO.Compression' (are you missing an assembly reference?)
You can try use DotNetZip instead. It has the same function as the ZipFile class.
|
0

Right click references, add a reference to framework assemblies System.IO.Compression and System.IO.Compression.FileSystem. Include using System.IO.Compression; and ensure you're using .NET Framework 4.5.

Comments

0

I'm late on this but it may help someone...

Add references to the files mentioned in other answers:

  • System.IO.Compression
  • System.IO.Compression.FileSystem

It probably will not work after adding those, so go into their properties and mark each ones "copy local" setting to "True".

Did the trick for me. :)

Comments

0

I had the same problem and looked for these namespaces in Assemblies -> Framework:
Just add the namespaces: System.IO.Compression & System.IO.Compression.FileSystem.

Here is the screen shot to make understanding/things easier:

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.