【问题标题】:Unzip File in VB.net [closed]在 VB.net 中解压缩文件 [关闭]
【发布时间】:2012-10-15 03:49:31
【问题描述】:

有人可以帮助我如何在 VB.Net解压缩 zip 文件吗?

我使用“进口 Shell32”

【问题讨论】:

    标签: vb.net unzip zipfile


    【解决方案1】:

    如果您查看这篇 CodeProject 文章,它应该会对您有所帮助。如果您遇到具体问题,您需要将代码和问题描述放在您的问题中。

    来自上面的文章:

    Sub UnZip()
        Dim sc As New Shell32.Shell()
        'Create directory in which you will unzip your files .
        IO.Directory.CreateDirectory("D:\extractedFiles") 
        'Declare the folder where the files will be extracted
        Dim output As Shell32.Folder = sc.NameSpace("D:\extractedFiles")
        'Declare your input zip file as folder  .
        Dim input As Shell32.Folder = sc.NameSpace("d:\myzip.zip")
        'Extract the files from the zip file using the CopyHere command .
        output.CopyHere(input.Items, 4)
    
    End Sub
    

    Folder.CopyHere 方法的链接


    或者,如果您使用的是 .Net 4.5,您可以使用 ZipFile Class

    链接示例:

    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
    

    【讨论】:

    • @kelvz 下次您选择答案时,还有另一个好问题,至少 +1。
    【解决方案2】:

    我建议你下载http://dotnetzip.codeplex.com/,然后像这样使用它(示例取自文档)。

    Dim ZipToUnpack As String = "C1P3SML.zip"  
    Dim TargetDir As String = "C1P3SML"  
    Console.WriteLine("Extracting file {0} to {1}", ZipToUnpack, TargetDir)   
    Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)   
        Dim e As ZipEntry   
        For Each e In zip1   
            e.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently)   
        Next  
    End Using  
    

    【讨论】:

    • 我的错误是“MyExtractProgress”
    • @kelvz 只需删除 AddHandler 行,其唯一目的是为您提供提取进度。这是一个单独的方法,直到您查看 dotnetzip codeplex 站点上的 vb.net 文档后才会显示
    • 无法将其读取为 ZipFile @MarkHall
    • @kelvzy 无法读取 zip 文件。
    猜你喜欢
    • 2013-08-14
    • 1970-01-01
    • 2013-04-27
    • 1970-01-01
    • 2019-03-23
    • 2012-03-08
    • 1970-01-01
    • 2021-06-12
    • 2010-11-04
    相关资源
    最近更新 更多