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
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