unzip using SharpZipLib

  • Thread starter Thread starter Aji Mathews via .NET 247
  • Start date Start date
A

Aji Mathews via .NET 247

Hi

I am using SharpZipLib. Could someone help with some sample code to unzip a file to a specified location.

Thanks
 
This uses the ZipInputStream method which provides sequential access
to each entry. The ZipFile method provides random access to each
entry.

The help files have lots of good examples too. They're C# but the
code is very similar to VB.NET.

Note that this was just test code I put together to verify the
decryption functionality since some people reported problems. This is
not really production quality in that it doesn't use try/finally to
ensure all of the streams are properly closed.

HTH,

Sam


Imports System.IO
Imports ICSharpCode.SharpZipLib.Zip

Module Module1

Sub Main()
Dim fileName As String = Path.GetFullPath("../AcapCopy.zip")
Dim destPath As String = Path.GetFullPath("../Unzipped/")

If Not Directory.Exists(destPath) Then
Directory.CreateDirectory(destPath)
Else
For Each s As String In Directory.GetFiles(destPath)
File.Delete(s)
Next
End If

Dim inStream As New ZipInputStream(File.OpenRead(fileName))
Dim outStream As FileStream

Dim entry As ZipEntry
Dim buff(2047) As Byte
Dim bytes As Integer

Do While True
entry = inStream.GetNextEntry()

If entry Is Nothing Then
Exit Do
End If

outStream = File.Create(destPath + entry.Name, 2048)

Do While True
bytes = inStream.Read(buff, 0, 2048)
If bytes = 0 Then
Exit Do
End If

outStream.Write(buff, 0, bytes)
Loop

outStream.Close()
Loop

inStream.Close()

End Sub

End Module


Hi

I am using SharpZipLib. Could someone help with some sample code to unzip a file to a specified location.

Thanks

B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top