在 VB.net 中解压文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12889044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unzip File in VB.net
提问by kelvz
Can someone help me how to unzipa zip file in VB.Net?
有人可以帮助我如何在VB.Net 中解压缩zip 文件吗?
im using "Imports Shell32"
我正在使用“导入 Shell32”
回答by Mark Hall
If you take a look at this CodeProjectarticle it should help you. If you are having specific problems you need to put the code and problem discription in your question.
如果您查看这篇CodeProject文章,它应该会对您有所帮助。如果您遇到特定问题,则需要将代码和问题描述放在您的问题中。
From above article:
从上面的文章:
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
link for Folder.CopyHere
Method
Folder.CopyHere
方法链接
Or if you are using .Net 4.5 you can use the ZipFile Class
或者,如果您使用的是 .Net 4.5,则可以使用ZipFile 类
Example from Link:
来自链接的示例:
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
回答by Karl-Johan Sj?gren
I would suggest that you download http://dotnetzip.codeplex.com/and then use it like this (example taken from the documentation).
我建议您下载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