ZIP Question

SIMIN

Regular
Joined
Mar 10, 2008
Messages
92
Hello
I have a question that might fall out of this forum scope!
But however, a friend in this forum recommended using this free open source ZIP component:

http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx

If anyone worked with that before and knows about it please help me, otherwise, simply disregard it :)

This assembly works great, I use it in VB.NET and have no problem adding file to zip archives.
But I have problems with extracting files from the archive!
Visual Basic:
Dim MyZip As New ZipInputStream(File.OpenRead(FileTextBox.Text))
Dim EntryObject As ZipEntry = MyZip.GetNextEntry()
While IsNothing(EntryObject) = False
    If EntryObject.IsFile And EntryObject.Name = "myfile.txt" Then

        'I don't know how to extacr each EntryObject here!!!

    End If
    EntryObject = MyZip.GetNextEntry()
End While
MyZip.Close()
 
You might find the FastZip class defined in the library to be quite useful - you could pretty much do something like

Visual Basic:
Dim fz as new FastZip
fs.ExtractZip(filetextbox.text, "c:\", "myfile.txt")
and it should work...

If you do need more control then you would need to read from the file / write to your file yourself...
Visual Basic:
        Dim MyZip As New ZipInputStream(File.OpenRead(FileTextBox.Text))
        Dim EntryObject As ZipEntry = MyZip.GetNextEntry

        While (IsNothing(EntryObject) = False)
            If EntryObject.IsFile And EntryObject.Name = "mtfile.txt" Then

                Dim MyFileStream As FileStream = New System.IO.FileStream("myfile.txt", FileMode.Create)
                Dim count As Integer
                Dim buffer(4096) As Byte

                count = MyZip.Read(buffer, 0, 4096)

                While count > 0
                    MyFileStream.Write(buffer, 0, count)
                    count = MyZip.Read(buffer, 0, 4096)
                End While

                MyFileStream.Close()

            End If
            EntryObject = MyZip.GetNextEntry
        End While
        MyZip.Close()
 
hello and thank you very much, you are just great :)
just one thing that buffer(4096) , if my file is for example 50 MB in size it won't have any problems?
I don't know why you set buffer to 4096.
Thanks :)
 
Hello and thanks.
Do you know why I cannot use wild chars here?

FastZIP.ExtractZip(RestoreTextBox.Text, "C:\", "*.txt")

I want to only extract .txt files OR all files except .bat files, do you think it's possible?!
 
Back
Top