Zip file SharpZipLib vb.net CF

J

JoseVB

Hi all, i need to decompress zip file... I used shapziplib, but all errors..

Error:

http://www.dpgavant.com/images/Image1.jpg

Sources:

http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx
http://www.icsharpcode.net/OpenSource/SD/forum/forum.asp?FORUM_ID=16

Does anybody have information about sharpziplib? or any other
suggestions for me?

Thank you very much...

JoseVB



Sample codes...

------------------------------------------------------------------------------

Imports System.IO
Imports ICSharpCode.SharpZipLib.Zip
Imports ICSharpCode.SharpZipLib.Zip.Compression
Imports ICSharpCode.SharpZipLib.Zip.Compression.Streams
Imports ICSharpCode.SharpZipLib.GZip

------------------------------------------------------------------------------

Sub Unzip(ByVal zipFile As String, ByVal UnzipToFolder As String)

Dim nByte As Integer
Dim s As New ZipInputStream(File.OpenRead(zipFile))
Dim entry As ZipEntry
Dim Zip_Data(2048) As Byte
Zip_Data(2048) = New Byte

entry = s.GetNextEntry

Do

Dim fs As New FileStream(Path.Combine(UnzipToFolder,
Path.GetFileName(entry.Name)), FileMode.Create)

Dim bw As New BinaryWriter(fs, System.Text.Encoding.ASCII)

nByte = s.Read(Zip_Data, 0, Zip_Data.GetLength(0))

While nByte > 0
bw.Write(Zip_Data, 0, nByte)
nByte = s.Read(Zip_Data, 0, Zip_Data.GetLength(0))
End While

fs.Close()
bw.Close()
entry = s.GetNextEntry

Loop While Not (entry Is Nothing)

s.Close()

End Sub

------------------------------------------------------------------------------


Public Sub Unzip2(ByVal ZipFile As String, ByVal UnzipToFolder As
String, ByVal Extract_File As String)
Dim Z_File As New ZipFile(System.IO.File.OpenRead(ZipFile))
Dim Z_Entry As ZipEntry = Z_File.GetEntry(Extract_File)
Dim nByte As Int32 = Z_Entry.Size

Dim Read_Stream As System.IO.Stream =
Z_File.GetInputStream(Z_Entry)

Dim Write_Stream As New
System.IO.FileStream(System.IO.Path.Combine(UnzipToFolder,
System.IO.Path.GetFileName(Z_Entry.Name)), System.IO.FileMode.Create)
Dim Bin_Write As New System.IO.BinaryWriter(Write_Stream,
System.Text.Encoding.ASCII)

Dim Zip_Data(2048) As Byte
Do While nByte > 0
nByte = Read_Stream.Read(Zip_Data, 0, Zip_Data.Length)
Bin_Write.Write(Zip_Data, 0, nByte)
Loop

Read_Stream.Close()
Bin_Write.Close()
Write_Stream.Close()
End Sub

------------------------------------------------------------------------------


Function UnZip3(ByVal filename As String, ByVal folderpath As String)

Dim FileZipUploaded As String = folderpath & "\" & filename
Dim ZipStream As New ZipInputStream(File.OpenRead(FileZipUploaded))
Dim TheEntry As ZipEntry = ZipStream.GetNextEntry()
Dim size As Integer

Do Until TheEntry Is Nothing
Dim data(1024) As Byte
Dim fileNameUnzipped As String = folderpath & "\" &
TheEntry.Name.ToString
Dim newfs As FileStream = File.Create(fileNameUnzipped)
Dim bw As New BinaryWriter(newfs)

Dim buffer(1024) As Byte
Dim length As Integer
Dim dataToRead As Long
dataToRead = 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
bw.Close()
newfs.Close()
TheEntry = ZipStream.GetNextEntry()
Loop

End Function

------------------------------------------------------------------------------


Public Sub Unzip4(ByVal ZipFile As String, ByVal UnzipToFolder As
String, _
ByVal Extract_File As String)
Dim z_file As ZipInputStream = _
New ZipInputStream(File.OpenRead(ZipFile))
Dim Z_Entry As ZipEntry

Do
Z_Entry = z_file.GetNextEntry
If Z_Entry.Name = Extract_File Then Exit Do
Loop

Dim nByte As Int32 = Z_Entry.Size

Dim Write_Stream As New
System.IO.FileStream(System.IO.Path.Combine(UnzipToFolder, _
System.IO.Path.GetFileName(Z_Entry.Name)),
System.IO.FileMode.Create)
Dim Bin_Write As New System.IO.BinaryWriter(Write_Stream,
System.Text.Encoding.ASCII)

Dim Zip_Data(2048) As Byte
Do While nByte > 0
nByte = z_file.Read(Zip_Data, 0, Zip_Data.Length)
Bin_Write.Write(Zip_Data, 0, nByte)
Loop

z_file.Close()
Bin_Write.Close()
Write_Stream.Close()
End Sub

------------------------------------------------------------------------------
 

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