Zip SharpZipLib examples for VB

C

CodeTalker

I am new to VB.NET and SharpZipLib for that matter. I need the ability
to zip a single file. I have found many examples of unzipping a zip
file but not one to actually zip one. If anyone has an example of this
I would GREATLY appreciate it.
 
G

Guest

not tested. but something like this......

Imports System.IO
Imports ICSharpCode.SharpZipLib.Checksums
Imports ICSharpCode.SharpZipLib.Zip
Imports ICSharpCode.SharpZipLib.GZip

Private Sub BtnZipItClick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Try

Dim objCrc32 As New Crc32()
Dim zos As ZipOutputStream

zos = New ZipOutputStream(File.Create(TextBox2.Text)) 'your
zipfile

Dim strFile As String

Dim strmFile As FileStream = File.OpenRead(yourFilename)
Dim abyBuffer(CInt(strmFile.Length - 1)) As Byte

strmFile.Read(abyBuffer, 0, abyBuffer.Length)
Dim objZipEntry As ZipEntry = New ZipEntry(strFile)

objZipEntry.DateTime = DateTime.Now
objZipEntry.Size = strmFile.Length
strmFile.Close()
objCrc32.Reset()
objCrc32.Update(abyBuffer)
objZipEntry.Crc = objCrc32.Value
zos.PutNextEntry(objZipEntry)
zos.Write(abyBuffer, 0, abyBuffer.Length)


zos.Finish()
zos.Close()


MessageBox.Show("Operation complete")


Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
 
C

CodeTalker

Thanks Chad. I really appreciate the help. I think that will work great
for what I need.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top