 |
 |

07-17-2006, 06:32 AM
|
|
Freshman
|
|
Join Date: Apr 2006
Location: Australia
Posts: 38
|
|
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).
|
|

07-17-2006, 07:06 AM
|
|
Freshman
|
|
Join Date: Mar 2006
Posts: 39
|
|
|

07-17-2006, 11:46 PM
|
|
Freshman
|
|
Join Date: Apr 2006
Location: Australia
Posts: 38
|
|
Quote:
|
Originally Posted by coin
|
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.
|

07-18-2006, 01:47 AM
|
|
Freshman
|
|
Join Date: Mar 2006
Posts: 39
|
|
|
Go the the code region Methods.Compression.Create.
There is a Public Overloads Shared Function CompressFile.
Its the one you use.
|
|

07-18-2006, 03:06 AM
|
|
Freshman
|
|
Join Date: Apr 2006
Location: Australia
Posts: 38
|
|
|
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.
|
|

07-18-2006, 06:25 AM
|
|
Centurion
|
|
Join Date: Feb 2006
Location: Harrison,AR
Posts: 169
|
|
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()
|
|

07-18-2006, 10:49 PM
|
|
Freshman
|
|
Join Date: Apr 2006
Location: Australia
Posts: 38
|
|
|

07-19-2006, 04:33 AM
|
|
Freshman
|
|
Join Date: Apr 2006
Location: Australia
Posts: 38
|
|
|
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.
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|