ZipFile is not declared in Visual basic 2017

Viewed 4323

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.

3 Answers

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.

Similar problem as the initial question. I followed the other solutions/comments above and ended up with having to do the following which has slight variations to the details:

  • Add System.IO.Compression.FileSystem to the Assembly references

  • Add both the below imports code lines to the beginning of the code:

    Imports System.IO '(Needed for additional file system functions used)
    Imports System.IO.Compression.ZipFile
    
  • Calling function without preceeding "ZipFile.":

    CreateFromDirectory(FileLocation1 & "\", FileLocation1 & ".zip")
    

I hope this may support others facing the same issue.

BR Fnk

Related