Can someone help me how to unzip a zip file in VB.Net?
im using "Imports Shell32"
If you take a look at this CodeProject article it should help you. If you are having specific problems you need to put the code and problem discription in your question.
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
Or if you are using .Net 4.5 you can use the ZipFile Class
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
I would suggest that you download http://dotnetzip.codeplex.com/ and then use it like this (example taken from the documentation).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With