Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net ZipFile未声明_.net_Vb.net_Visual Studio 2017_Zip - Fatal编程技术网

.net ZipFile未声明

.net ZipFile未声明,.net,vb.net,visual-studio-2017,zip,.net,Vb.net,Visual Studio 2017,Zip,我正试图在VB.Net中使用Zipfile类,但找不到库。我正在测试我在几个互联网站点上找到的以下示例代码: Imports System.IO Imports System.IO.Compression Module Module1 Sub Main() Dim startPath As String = "c:\example\start" Dim zipPath As String = "c:\example\result.zip"

我正试图在
VB.Net
中使用Zipfile类,但找不到库。我正在测试我在几个互联网站点上找到的以下示例代码:

Imports System.IO
Imports System.IO.Compression

Module Module1
    Sub Main()
        Dim startPath As String = "c:\example\start"
        Dim zipPath As String = "c:\example\result.zip"
        Dim extractPath As String = "c:\example\extract"

        ZipFile.CreateFromDirectory(startPath, zipPath)

        ZipFile.ExtractToDirectory(zipPath, extractPath)
    End Sub
End Module
我得到了错误“ZipFile未声明”。我知道这是4.5的新版本,并且尝试将我的项目设置为4.5和4.62,但没有成功

我也尝试过使用ZipArchive,我在其他搜索中也找到了:

Sub Compress(filename As String, zippedFile As String)
    If IO.File.Exists(zippedFile) Then IO.File.Delete(zippedFile)

    If IO.File.Exists(filename) Then
        Using archive As ZipArchive = Open(zippedFile, ZipArchiveMode.Create)
            archive.CreateEntryFromFile(filename, Path.GetFileName(filename), CompressionLevel.Fastest)
        End Using
    End If
End Sub

ZipArchive也找不到。有人能告诉我如何解决这两个例子中的一个错误吗?谢谢。

为了使用ZipFile类,您必须在项目中添加对System.IO.Compression.FileSystem程序集的引用;否则,正如您所注意到的,在尝试编译时会收到以下错误消息:
名称“ZipFile”在当前上下文中不存在。


有关更多信息,请参见:

好的。这是有道理的。但是我以前没有在项目中添加对程序集的引用。您能给我更详细的步骤说明如何在VS 2017中做到这一点吗?我检查了那个链接,它说我需要汇编:System.IO.Compression.FileSystem(在System.IO.Compression.FileSystem.dll中)右键单击项目中的引用,然后单击add。然后查找该dll。