Search code examples
visual-studiozip

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.


Solution

  • 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.