1
votes

I'am trying to unzip files from .zip file in C# (Forms App) I got something like this:

System.IO.Compression.ZipFile.ExtractToDirectory(zipPath, extractPath);

i have strings zip and extract Path but i have an error "CS0234". My libraries:

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.Media;
using System.IO.Compression;
using System.IO;

Any ideas?

3
Do you have a reference to the System.IO.Compression.FileSystem assembly? Read the remarks. - dr.null
If you already have using System.IO.Compression you don't need to add it in front of the rest. It should just be "ZipFile.ExtractToDirectory(zipPath, extractPath);" - Sarah Cox
I got "ZipFile does not exist in current context - Jake
Then it's most likely what @dr.null suggested. Expand the references in your project and see if System.IO.Compression.FileSystem is there - Sarah Cox

3 Answers

1
votes

The following doc confirms what has been suggested in the comments, when it says the following:

The following examples show some of the operations you can perform with compressed files. These examples require the following NuGet packages to be added to your project:

  • System.IO.Compression
  • System.IO.Compression.ZipFile

If you're using .NET Framework, add references to these two libraries to your project:

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

You need to add an assembly reference to System.IO.Compression.FileSystem.

0
votes

Don't forget to reference System.IO.Compresssion and System.IO.Compression.FileSystem in your project.

-1
votes

Ok i got an answer! It was just an Visual Studio error. I recopied the code and it worked!