Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > SharpZipLib


Reply
 
Thread Tools Display Modes
  #1  
Old 07-17-2006, 06:32 AM
ben_dover ben_dover is offline
Freshman
 
Join Date: Apr 2006
Location: Australia
Posts: 38
Default SharpZipLib


Hi I'm currently trying to write the last part of my little update application for my bigger project.

Anyway I've downloaded SharpZipLib and have been hacking away at it with no results, I've been converting their C# code examples to vb.net but still haven't gotten anywhere.

What I'd like to be done is have a class/sub whatever where I just pass a filename to it and it extracts to a directory that has been hardcoded in. The zip files do contain folders (so I only have to extract to the one directory, not multiple).
Reply With Quote
  #2  
Old 07-17-2006, 07:06 AM
coin coin is offline
Freshman
 
Join Date: Mar 2006
Posts: 39
Default

Dont hustle. this is exactlyy what u want.
http://www.vbforums.com/showthread.p...&highlight=zip
Reply With Quote
  #3  
Old 07-17-2006, 11:46 PM
ben_dover ben_dover is offline
Freshman
 
Join Date: Apr 2006
Location: Australia
Posts: 38
Default

Quote:
Originally Posted by coin
Dont hustle. this is exactlyy what u want.
http://www.vbforums.com/showthread.p...&highlight=zip
I was hoping not to have to use 2 libraries for the 1 thing but awell, it's too complicated too just write a sub for with my level of experience.

Edit: How do I specify the files I want to compress using
Code:
Wunnel.IO.Compression.Zip.CompressFiles(sourceNames() As String, archiveName As String)
I figure sourceNames() has to be a string array but how do i do that? I tried:
Code:
Dim zipFiles(1) As String = Application.StartupPath & "\folder\eg.dll"
        Dim zipFiles(2) As String = Application.StartupPath & "\folder\eg.exe"

CompressFiles(zipFiles(), "myArchive.zip")

Last edited by ben_dover; 07-18-2006 at 12:47 AM.
Reply With Quote
  #4  
Old 07-18-2006, 01:47 AM
coin coin is offline
Freshman
 
Join Date: Mar 2006
Posts: 39
Default

Go the the code region Methods.Compression.Create.
There is a Public Overloads Shared Function CompressFile.
Its the one you use.
Reply With Quote
  #5  
Old 07-18-2006, 03:06 AM
ben_dover ben_dover is offline
Freshman
 
Join Date: Apr 2006
Location: Australia
Posts: 38
Default

To be honest I'm not sure what you mean but, I know how to use "CompressFile" and "CompressFolder" but not "CompressFiles", you see I want multiple files in the one archive.
Reply With Quote
  #6  
Old 07-18-2006, 06:25 AM
Jabo Jabo is offline
Centurion
 
Join Date: Feb 2006
Location: Harrison,AR
Posts: 169
Default

This is an example of zipping multiple files, defined by type, within a folder using the SharpZipLib. Also has variable compression and password. You
Code:
Public Shared Sub Zip(ByVal type1 As String, ByVal type2 As String, ByVal FileName As String, ByVal Compression As Integer, ByVal password As String, ByVal directory As String) Dim oFiles() As System.IO.FileInfo Dim i As Int32 Dim strZippedFile As String = FileName Dim nBlockSize As Integer = 10 Dim strmStreamToZip As System.IO.FileStream Dim strmZipFile As System.IO.FileStream Dim strmZipStream As Zip.ZipOutputStream Dim myZipEntry As Zip.ZipEntry Dim abyBuffer(nBlockSize) As Byte Dim nSize As System.Int32 Dim oDir As New System.IO.DirectoryInfo(directory) oFiles = oDir.GetFiles strmZipFile = System.IO.File.Create(My.Application.Info.DirectoryPath & "\" & strZippedFile) strmZipStream = New Zip.ZipOutputStream(strmZipFile) For i = 0 To oFiles.Length - 1 Dim strFileToZip As String = (oFiles(i).FullName.ToString) strmStreamToZip = New System.IO.FileStream(strFileToZip, System.IO.FileMode.Open, System.IO.FileAccess.Read) If oFiles(i).Extension = type1 Or oFiles(i).Extension = type2 Then strmZipStream.Password = password strmZipStream.SetLevel(Compression) myZipEntry = New Zip.ZipEntry(System.IO.Path.GetFileName(strFileToZip)) strmZipStream.PutNextEntry(myZipEntry) nSize = strmStreamToZip.Read(abyBuffer, 0, abyBuffer.Length) strmZipStream.Write(abyBuffer, 0, nSize) Try While (nSize < strmStreamToZip.Length) Dim nSizeRead As Integer My.Application.DoEvents() nSizeRead = strmStreamToZip.Read(abyBuffer, 0, abyBuffer.Length) strmZipStream.Write(abyBuffer, 0, nSizeRead) nSize = nSize + nSizeRead End While Catch Ex As System.Exception Throw Ex End Try strmStreamToZip.Close() oFiles(i).Delete() End If Next strmZipStream.Finish() strmZipStream.Close() strmZipStream.Dispose()
Reply With Quote
  #7  
Old 07-18-2006, 10:49 PM
ben_dover ben_dover is offline
Freshman
 
Join Date: Apr 2006
Location: Australia
Posts: 38
Default

Thanks.
Reply With Quote
  #8  
Old 07-19-2006, 04:33 AM
ben_dover ben_dover is offline
Freshman
 
Join Date: Apr 2006
Location: Australia
Posts: 38
Default

For anyone using SharpZipLib and Wunnel.IO and you try to zip up multiple files using CompressFiles(), I don't know how to use that method so I just did CompressFolder() and set IncludePath to PathTypeNone so it leaves out all folders when zipping.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->