Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZipFile is not declared in Visual basic 2017

I'm trying to make a little test app to compress and extract folders, and here is my code :

Imports System.IO
Imports System.IO.Compression

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        FolderBrowserDialog1.ShowDialog()
        If Not FolderBrowserDialog1.SelectedPath = "" Then
            Dim startPath As String = FolderBrowserDialog1.SelectedPath
            Dim zipPath As String = "C:\Users\LENOVO\Desktop\result.zip"
            ZipFile.CreateFromDirectory(startPath, zipPath)
        End If
    End Sub
End Class

And the error is in the ZipFile command :

ZipFile is not declared. it may be inaccessible due to its protection level.

I'v searched a lot, and my target framework is 4.5.2 so Zip file should be supported, and i'm using visual studio 2017.

Any help will be appreciated.

like image 801
Mousa Alfhaily Avatar asked Jan 22 '26 11:01

Mousa Alfhaily


2 Answers

I solved the problem with adding a reference, just go to Project tab --> Add Reference --> Assemblies tab and then select System.IO.Compression.FileSystem and add it, and it should work, here is some images too :

enter image description here enter image description here

Hope someone will find this useful.

like image 198
Mousa Alfhaily Avatar answered Jan 24 '26 03:01

Mousa Alfhaily


This may not affect everyone, but this is what I had to do to solve this issue (leaving this here as a self-note as much as anything).

I ended up having to find System.IO.Compression.dll, System.IO.Compression.Filesystem.DLL, and System.IO.Compression.ZipFile.dll on my computer and move them to the BIN folder of the site I'm working on. As soon as I did so, any "not declared" errors disappeared.

like image 28
SEFL Avatar answered Jan 24 '26 03:01

SEFL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!