在VB.net中解压缩文件

kel*_*lvz 3 vb.net unzip zipfile

有人可以帮我解决如何在VB.Net中解压缩 zip文件的问题吗?

即时通讯使用"Imports Shell32"

Mar*_*all 20

如果你看看这个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
Run Code Online (Sandbox Code Playgroud)

Folder.CopyHere方法链接


或者,如果您使用的是.Net 4.5,则可以使用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
Run Code Online (Sandbox Code Playgroud)


Kar*_*ren 7

我建议你下载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  
Run Code Online (Sandbox Code Playgroud)