Home All Groups Group Topic Archive Search About

Unzipping in Visual Basic .Net

Author
4 Apr 2006 3:53 PM
ILCSP
Hello, I've been trying to unzip a file in Visual Basic .Net (03) but
I'm getting an error.  I do get the destination directory and I do get
the first extracted file, but then it stops and I get an wrong local
header signature error.  I've added the SharpZipLib.dll library to my
project, so that's what I'm using.  The zip files contains 9 text
files.

This is the error I get:
An unhandled exception of type 'ICSharpCode.SharpZipLib.ZipException'
occurred in sharpziplib.dll
Additional information: Wrong Local header signature-1826153501

I have the following in the top of my code:
Imports System
Imports System.IO
Imports ICSharpCode.SharpZipLib.Zip

This is what I have in my button:

Private Sub btnUnzip_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUnzip.Click

        Dim fileName As String = Path.GetFullPath("c:\testing.zip")
        Dim destPath As String = Path.GetFullPath("c:\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()    <==== This is where the
error occurs!
            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)
                MsgBox("writing")
            Loop
            outStream.Close()
        Loop
        inStream.Close()
    End Sub

Any help would be greatly appreciated.

Thanks.

Author
4 Apr 2006 4:31 PM
ILCSP
Hello again, I just want to point out that I created a new zip file
with Winzip with 2 text files in it and tested the code and it worked.
However, when I tested again the Zip file I actually need to unzip, I
still get the  Wrong Local header signature-1826153501 error.
Author
4 Apr 2006 5:41 PM
zacks
Can WinZip open the errant zip file?