Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unzip File in VB.net [closed]

Tags:

vb.net

zip

unzip

Can someone help me how to unzip a zip file in VB.Net?

im using "Imports Shell32"

like image 905
kelvz Avatar asked Oct 15 '12 03:10

kelvz


2 Answers

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
like image 93
Mark Hall Avatar answered Oct 09 '22 17:10

Mark Hall


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  
like image 37
Karl-Johan Sjögren Avatar answered Oct 09 '22 18:10

Karl-Johan Sjögren