I'm going to explain you guys, how to unzip .rar/.zip/.7z and so on with visual basic.
We first off need the SharpZibLibrary, which can be found in attachments.
After downloading it SharpZipLib_0855_Bin.zip, unrar it. Now start a new vb project.
Now add the .dll to your project.
Solution-Explorer > Righ***1ck on your project > Add Reference > Browse > Select the .dll from the "net-20" folder.
Add the following namespace
Code:
Imports ICSharpCode.SharpZipLib
Make 1 Textbox and 2 Buttons.
Textbox1 = Path to the folder where the archive is in
Button1 = FolderBrowserDialog to browse the archive
Button2 = Unzipping the archive
Set the openfiledialog...
On button1_click event...
Code:
Dim fbd as folderbrowserdialog
fbd.showdialog
textbox1.text = fbd.selectedpath
On button2_click event...
Declare a fastzip
Code:
Dim unz as zip.fastzip()
Now to unzip something...
Code:
unzip.ExtractZip("ZipDirectory", "targetdirectory", "filefilter")
Let's say we want to save it to the desktop...
Code:
Dim desktop as string
on Form_Load
Code:
desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) ' getting desktop path of any computer
In our case it is...
Code:
unz.ExtractZip(Textbox1.text & "\Filename"", desktop & "\Foldername"", "")
To set the filename / Desktop directory you can do the following...
Code:
Dim directory As String = System.IO.Path.Combine(desktop, "Foldername to save it to")
Dim file As String = System.IO.Path.Combine(textbox1.Text, "foldernametounzip.zip")
-> ->
Code:
unz.ExtractZip(file, directory, "")
This might be a bit confusing, I am currently confusing myself lul...here is how it should look like...
Code:
Imports ICSharpCode.SharpZipLib
Public Class Form1
Dim desktop As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fbd As New FolderBrowserDialog
fbd.ShowDialog()
filepath.Text = fbd.SelectedPath
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim directory As String = System.IO.Path.Combine(desktop, "Foldername to save it in")
Dim file As String = System.IO.Path.Combine(filepath.Text, "FileToUnzip.zip")
Dim unz As New Zip.FastZip()
unz.ExtractZip(file, directory, "")
Catch
MsgBox(ErrorToString)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
End Sub
End Class
You sure can do a lot with the sharpzip library, not just unzipping. I hope you did understand me ^.-