These are the highest level classes in the C1Zip library. They allow you to create and manage zip files. Using zip files to store application data provides the following benefits:
The C1ZipFile class encapsulates a zip file. After you create a C1ZipFile object, you can attach it to an existing zip file or tell it to create a new empty zip file for you. For example:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
' Create a C1ZipFile object. Dim myZip As New C1ZipFile() ' Create a new (empty) zip file. myZip.Create("New.zip") ' Open an existing zip file. myZip.Open("Old.zip") |
To write code in C#
C# |
Copy Code
|
---|---|
// Create a C1ZipFile object. C1ZipFile myZip = new C1ZipFile(); // Create a new (empty) zip file. myZip.Create("New.zip"); // Open an existing zip file. myZip.Open("Old.zip"); |
After you have created or opened a zip file, use the Entries collection to inspect the contents of the zip file, or to add, expand, and delete entries. For example:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
myZip.Entries.Add("MyData.txt") myZip.Entries.Add("MyData.xml") myZip.Entries.Add("MyData.doc") Dim zipEntry As C1ZipEntry For Each zipEntry In myZip.Entries Console.WriteLine(zipEntry.FileName) Next zipEntry myZip.Open("Old.zip"); |
To write code in C#
C# |
Copy Code
|
---|---|
myZip.Entries.Add("MyData.txt"); myZip.Entries.Add("MyData.xml"); myZip.Entries.Add("MyData.doc"); foreach (C1ZipEntry zipEntry in myZip.Entries) Console.WriteLine(zipEntry.FileName); |
The C1ZipEntry class exposes properties and methods that describe each entry, including its original file name, size, compressed size, and so on. It also has a OpenReader method that returns a stream object, so you can read the entry contents without expanding it first.