Ok, I solved the zip error, but I can't unzip

  • Thread starter Jean Christophe Avard
  • Start date
J

Jean Christophe Avard

Hi! Finally I figure out what was wrong... "objZipEntry.size = strmFile" I wasn't giving the right file length... But now, I have issue with the unzip function... I can't unzip it, the unzip function return true but its invalid parameter when I try to set the image to the picture box....

Private Overloads Function Unzip(ByVal strSource As String, ByVal
strFileToExtract As String, ByRef newms As MemoryStream) As Boolean

If File.Exists(strSource) Then

Dim ZipStream As ZipInputStream

Try

ZipStream = New ZipInputStream(File.OpenRead(strSource))

ZipStream.Password = "your own prefered password here"

Dim TheEntry As ZipEntry = ZipStream.GetNextEntry()

Dim size As Integer

Do Until TheEntry Is Nothing

If Path.GetFileName(TheEntry.Name) = strFileToExtract Then

Dim data(1024) As Byte

newms = New MemoryStream

Dim bw As New BinaryWriter(newms)

Dim buffer(1024) As Byte

Dim length As Integer

Dim dataToRead As Long = TheEntry.Size

While dataToRead > 0

length = ZipStream.Read(buffer, 0, 1024)

bw.Write(buffer, 0, length)

ReDim buffer(1024) ' Clear the buffer

dataToRead = dataToRead - length

End While

Return True

End If

TheEntry = ZipStream.GetNextEntry()

Loop

Catch e As Exception

Finally

ZipStream.Close()

End Try

End If

End Function
 
M

m.posseth

Hello Jean

i have just send you a working example , inclusive the way to bind the
unzipped stream to a picturebox

i hope it helps :)


regards

Michel Posseth



Hi! Finally I figure out what was wrong... "objZipEntry.size = strmFile" I
wasn't giving the right file length... But now, I have issue with the unzip
function... I can't unzip it, the unzip function return true but its invalid
parameter when I try to set the image to the picture box....

Private Overloads Function Unzip(ByVal strSource As String, ByVal
strFileToExtract As String, ByRef newms As MemoryStream) As Boolean

If File.Exists(strSource) Then

Dim ZipStream As ZipInputStream

Try

ZipStream = New ZipInputStream(File.OpenRead(strSource))

ZipStream.Password = "your own prefered password here"

Dim TheEntry As ZipEntry = ZipStream.GetNextEntry()

Dim size As Integer

Do Until TheEntry Is Nothing

If Path.GetFileName(TheEntry.Name) = strFileToExtract Then

Dim data(1024) As Byte

newms = New MemoryStream

Dim bw As New BinaryWriter(newms)

Dim buffer(1024) As Byte

Dim length As Integer

Dim dataToRead As Long = TheEntry.Size

While dataToRead > 0

length = ZipStream.Read(buffer, 0, 1024)

bw.Write(buffer, 0, length)

ReDim buffer(1024) ' Clear the buffer

dataToRead = dataToRead - length

End While

Return True

End If

TheEntry = ZipStream.GetNextEntry()

Loop

Catch e As Exception

Finally

ZipStream.Close()

End Try

End If

End Function
 

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

Top