Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 2.0

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
.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.

 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.
 EnumerationDescription
Public enumerationCompressionMode Specifies whether to compress or decompress the underlying stream.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
.Net 1.1 Compression Technique.      pmasclark   |   Edit   |   Show History

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 What's this?: Add a tag
Flag as ContentBug
Another 1.* technique, using only managed .NET code      Drew Noakes   |   Edit   |   Show History

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 What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker