SIMIN Posted July 1, 2008 Posted July 1, 2008 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() Quote
Administrators PlausiblyDamp Posted July 1, 2008 Administrators Posted July 1, 2008 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() Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
SIMIN Posted July 1, 2008 Author Posted July 1, 2008 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 :) Quote
Nate Bross Posted July 1, 2008 Posted July 1, 2008 Each time through the loop it will read 4096 bytes of your file. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Administrators PlausiblyDamp Posted July 1, 2008 Administrators Posted July 1, 2008 No reason, 4K just seemed a nice round number. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
SIMIN Posted July 2, 2008 Author Posted July 2, 2008 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?! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.