Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!

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

  • Administrators
Posted

You might find the FastZip class defined in the library to be quite useful - you could pretty much do something like

 

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


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

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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

Posted
Each time through the loop it will read 4096 bytes of your file.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...