有人可以帮助我解压缩 VB.Net 中的zip文件吗?
我正在使用“Imports Shell32”
答案 0 :(得分:19)
如果您查看这篇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
的链接
或者,如果您使用的是.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
答案 1 :(得分:6)
我建议你下载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