首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未声明ZipFile

未声明ZipFile
EN

Stack Overflow用户
提问于 2018-03-05 22:09:28
回答 1查看 795关注 0票数 0

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

代码语言:javascript
复制
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,我在其他搜索中发现了这一点:

代码语言:javascript
复制
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也找不到。有人能告诉我如何解决这两个例子中的一个错误吗?谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-05 22:28:22

为了使用System.IO.Compression.FileSystem类,必须在项目中添加对ZipFile程序集的引用;否则,正如您注意到的那样,在尝试编译时将得到以下错误消息:The name 'ZipFile' does not exist in the current context.

有关更多信息,请参见:https://msdn.microsoft.com/en-us/library/system.io.compression.zipfile(v=vs.110).aspx

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49120325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档