OK, this isn't my code, I found it as an example, so I haven't tested it.
It uses a 3rd party library called
SharpZipLib. You will need to download it. It can be registered as an assembly.
Here's some code:
- Public Sub ExtractArchive(ByVal zipFilename As String, ByVal ExtractDir As String)
-
Dim Redo As Integer = 1
-
Dim MyZipInputStream As ZipInputStream
-
Dim MyFileStream As FileStream
-
MyZipInputStream = New ZipInputStream(New FileStream(zipFilename, FileMode.Open, FileAccess.Read))
-
Dim MyZipEntry As ZipEntry = MyZipInputStream.GetNextEntry
-
Directory.CreateDirectory(ExtractDir)
-
While Not MyZipEntry Is Nothing
-
If (MyZipEntry.IsDirectory) Then
-
Directory.CreateDirectory(ExtractDir & "\" & MyZipEntry.Name)
-
Else
-
If Not Directory.Exists(ExtractDir & "\" & _
-
Path.GetDirectoryName(MyZipEntry.Name)) Then
-
Directory.CreateDirectory(ExtractDir & "\" & _
-
Path.GetDirectoryName(MyZipEntry.Name))
-
End If
-
MyFileStream = New FileStream(ExtractDir & "\" & _
-
MyZipEntry.Name, FileMode.OpenOrCreate, FileAccess.Write)
-
Dim count As Integer
-
Dim buffer(4096) As Byte
-
count = MyZipInputStream.Read(buffer, 0, 4096)
-
While count > 0
-
MyFileStream.Write(buffer, 0, count)
-
count = MyZipInputStream.Read(buffer, 0, 4096)
-
End While
-
MyFileStream.Close()
-
End If
-
Try
-
MyZipEntry = MyZipInputStream.GetNextEntry
-
Catch ex As Exception
-
MyZipEntry = Nothing
-
End Try
-
End While
-
If Not (MyZipInputStream Is Nothing) Then MyZipInputStream.Close()
-
If Not (MyFileStream Is Nothing) Then MyFileStream.Close()
-
End Sub