Class Library Reference


.NET Framework Class Library
System.IO.Compression Namespace

Note: This namespace is new in the .NET Framework version 2.0.

The System.IO.Compression namespace contains classes that provide basic compression and decompression services for streams.

Classes

 ClassDescription
Public classDeflateStreamProvides methods and properties for compressing and decompressing streams using the Deflate algorithm.
Public classGZipStreamProvides methods and properties used to compress and decompress streams.
Enumerations

 EnumerationDescription
Public enumerationCompressionMode Specifies whether to compress or decompress the underlying stream.
Tags :


Community Content

pmasclark
.Net 1.1 Compression Technique.

This is a method that will compress a directory of files using the ShellClass and the Shell32 api.

    Public Sub startCompression(ByVal stateInfo As Object)
 
      Dim strArgs As String = ""
      Dim strdest As String = ""
      
      '----- Check the file for a .zip extenstion.
      strdest += strDestinationFile
      If System.IO.Path.GetExtension(strdest).ToUpper.EndsWith(".ZIP") = False Then
        strdest += ".zip"
      End If
      If strdest.IndexOf(" ") <> -1 Then
        strdest = """" & strdest & """"
      End If
 
      '----- Binary Array representing a zip file header.
      Dim emptyZip As Byte() = New Byte() {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
 
      '----- Write out the zip file
      Dim fs As FileStream = File.Create(Me.strDestinationFile)
      fs.Write(emptyZip, 0, emptyZip.Length)
      fs.Flush()
      fs.Close()
      fs = Nothing
      
 
      Dim sc As ShellClass = New ShellClass
      Dim src As Shell32.Folder = sc.NameSpace(Me.strSourceDir)
      Dim dst As Shell32.Folder = sc.NameSpace(Me.strDestinationFile)
      '----- Begining File Compression in System Controlled Thread
      dst.CopyHere(src, 20)
     
      '----- Sleep to allow the compression thread to begin execution
      System.Threading.Thread.CurrentThread.Sleep(5000) ' 5 seconds is usually more than enough
    End Sub
Tags :

Drew Noakes
Another 1.* technique, using only managed .NET code

There's a GPL library for compression, implemented entirely in managed code.  I've found this library very easy to use in the past.

http://www.icsharpcode.net/OpenSource/SharpZipLib/

 

Tags :

Page view tracker