By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 1,026 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

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

"Jean Christophe Avard" <NO***@M.BITCH> wrote in message
news:Oe**************@tk2msftngp13.phx.gbl...
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
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.