EACompression Namespace References


EACompression namespace contains classes that allow you to compress or decompress zip file. The classes in this namespace can be used from ASP.NET or any managed application.

Classes

Class Description
ZipArchive Provides properties and methods for presenting a zip archive.
ZipFile Provides properties and methods for presenting a zipped file.
CorruptedZipFileException Represents errors that the current zip archive is corrupted.
InvalidZipPasswordException Represents invalid password error.
CompressionFormat Provides enumered values for file format.
UserTerminatedException Represents error that file compression/decompression is cancelled by user.

Example

[Visual Basic, C#, C++] The following example demonstrates how to compress/decompress file with EACompression Zip Component. Events are not shown here, please refer to Samples section to get the one of the file of EACompression.

[Visual Basic]
Imports EACompression

Sub Unzip()
    Try
        Dim oZip As New ZipArchive("TryIt")
        oZip.Load("c:\test.zip")
        Dim zs() As ZipFile = oZip.Files
        Dim count As Integer = zs.Length
        Dim password As String = ""
        Dim overwrite As Boolean = True

        For i As Integer = 0 To count - 1
            Dim z As ZipFile = zs(i)
            oZip.ExtractTo(z, password, "c:\unzipped", overwrite)
        Next

        'another way is:
        'oZip.ExtractAll( "c:\uuzipped", password ) 

        'if you want to remove one of the file from this zip archive.
        'oZip.Remove( zs(0) )
    Catch ep As Exception
        Console.Write(ep.Message)
    End Try
End Sub

Sub Zip()
    Try
        Dim oZip As New ZipArchive("TryIt")
        oZip.Create("c:\test.zip", True)   'create a new zip file
        Dim password As String = ""
        'add a single file to zip file.
        oZip.AddFile("c:\test.gif", "test.gif", password)
        'add all files and sub-directory in temp folder to zip archive
        oZip.AddDirectory("c:\temp", password)
    Catch ep As Exception
        Console.Write(ep.Message)
    End Try
End Sub

[C#]
using System;
using System.Collections;
using EACompression;

void Unzip( )
{
    try
    {
        ZipArchive oZip = new ZipArchive( "TryIt" );
        oZip.Load( "c:\\test.zip" );

        ZipFile [] zs = oZip.Files;
        int count = zs.Length;
        string password = "";
        bool overwrite = true;
        for( int i = 0; i < count; i++ )
        {
            ZipFile z = zs[i];
            oZip.ExtractTo( z, password, "c:\\unzipped", overwrite );
        }

        //another way is:
        //oZip.ExtractAll( "c:\\uuzipped", password ); 

        //if you want to remove one of the file from this zip archive.
        //oZip.Remove( zs[0] );
    }
    catch( Exception ep )
    {
        Console.Write( ep.Message );
    }
}

void Zip()
{
    try
    {
        ZipArchive oZip = new ZipArchive( "TryIt" );
        oZip.Create( "c:\\test.zip", true ); //create a new zip file;
        string password = "";
        //add a single file to zip file.
        oZip.AddFile( "c:\\test.gif", "test.gif", password );
        //add all files and sub-directory in temp folder to zip archive
        oZip.AddDirectory( "c:\\temp", password ); 
    }
    catch( Exception ep )
    {
        Console.Write( ep.Message );
    }
}

[C++]
using namespace System;
using namespace System::Collections;
using namespace EACompression; 

void Unzip( )
{
    try
    {
        ZipArchive *oZip = new ZipArchive( S"TryIt" );
        oZip->Load( S"c:\\test.zip" );

        ZipFile *zs[] = oZip->Files;
        int count = zs->Length;
        String *password = S"";
        bool overwrite = true;
        for( int i = 0; i < count; i++ )
        {
            ZipFile *z = zs[i];
            oZip->ExtractTo( z, password, S"c:\\unzipped", overwrite );
        }

        //another way is:
        //oZip->ExtractAll( S"c:\\uuzipped", password ); 

        //if you want to remove one of the file from this zip archive.
        //oZip->Remove( zs[0] );
    }
    catch( Exception *ep )
    {
        Console::Write( ep->Message );
    }
}

void Zip()
{
    try
    {
        ZipArchive *oZip = new ZipArchive( S"TryIt" );
        oZip->Create( S"c:\\test.zip", true ); //create a zip file;
        String *password = S"";
        //add a single file to zip file.
        oZip->AddFile( S"c:\\test.gif", S"test.gif", password );
        //add all files and sub-directory in temp folder to zip archive
        oZip->AddDirectory( S"c:\\temp", password ); 
    }
    catch( Exception *ep )
    {
        Console::Write( ep->Message );
    }
}