Provides properties and methods for presenting zip archive.
System.Object
EACompression.ZipArchive
[Visual Basic] Public Class ZipArchive
[C#] public class ZipArchive
[C++] public __gc class ZipArchive
[JScript] public class ZipArchive
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. All instance members are not guaranteed to be thread safe.
ZipArchive Constructor | Initializes a new instance of the ZipArchive class. |
Public Properties
Files | Gets all files information in current zip file. |
Format | Gets or sets the archive file format. |
Public Methods
AddDirectory | Adds a directory including sub-directories and files to current zip file. |
AddFile | Adds a single file to current zip file. |
Create | Creates a new zip file. |
ExtractAll | Unzips all files in current zip file to specified folder. |
ExtractTo | Unzips a single file to local disk or byte arrray or stream. |
Load | Loads an existed zip file to current object to operate. |
Remove | Removes a single or multiple file from current zip file. |
SaveAs | Saves current zip file to another location. |
Public Events
OnCompressing | Occurs when a file is being compressed to current zip file. |
OnExtracting | Occurs when a file is being extracted from current zip file. |
OnLoading | Occurs when the object is loading a zip archive. |
OnOverwrite | Occurs when an existed file will be overwrited. |
OnPasswordError | Occurs when the decrypting password is incorrect. |
OnRemoving | Occurs when a file is being removed from current zip file. |
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 full samples 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 ); } }