You are on page 1of 287

ComponentOne

Zip for .NET

Copyright 1987-2015 GrapeCity, Inc. All rights reserved.

ComponentOne, a division of GrapeCity


201 South Highland Avenue, Third Floor
Pittsburgh, PA 15206 USA

Website:
Sales:
Telephone:

http://www.componentone.com
sales@componentone.com
1.800.858.2739 or 1.412.681.4343 (Pittsburgh, PA USA Office)

Trademarks
The ComponentOne product name is a trademark and ComponentOne is a registered trademark of GrapeCity, Inc.
All other trademarks used herein are the properties of their respective owners.

Warranty
ComponentOne warrants that the media on which the software is delivered is free from defects in material and
workmanship, assuming normal use, for a period of 90 days from the date of purchase. If a defect occurs during this
time, you may return the defective media to ComponentOne, along with a dated proof of purchase, and
ComponentOne will replace it at no charge. After 90 days, you can obtain a replacement for the defective media by
sending it and a check for $25 (to cover postage and handling) to ComponentOne.
Except for the express warranty of the original media on which the software is delivered is set forth here,
ComponentOne makes no other warranties, express or implied. Every attempt has been made to ensure that the
information contained in this manual is correct as of the time it was written. ComponentOne is not responsible for
any errors or omissions. ComponentOnes liability is limited to the amount you paid for the product. ComponentOne
is not liable for any special, consequential, or other damages for any reason.

Copying and Distribution


While you are welcome to make backup copies of the software for your own use and protection, you are not
permitted to make copies for the use of anyone else. We put a lot of time and effort into creating this product, and
we appreciate your support in seeing that it is used by licensed users only.

Table of Contents
Zip for .NET Overview .............................................................................................................. 9
Help with WinForms Edition ................................................................................................ 9
Creating a Mobile Device Application................................................................................... 9
Migrating a Zip for .NET Project to Visual Studio 2005........................................................ 10
Key Features .......................................................................................................................... 11
Zip for .NET Fundamentals..................................................................................................... 13
High Level: C1ZipFile, C1ZipEntry and C1ZipEntryCollection Classes ................................... 13
Medium Level: C1ZStreamReader and C1ZStreamWriter Classes ....................................... 15
Low Level: ZStream Class ................................................................................................... 17
Zip for Mobile Devices Fundamentals .................................................................................... 17
Zip for .NET Samples .............................................................................................................. 18
Zip for .NET Task-Based Help ................................................................................................. 19
Compressing Datasets ....................................................................................................... 20
Compressing an Entire Folder into a Zip File....................................................................... 22
Creating a Zip File with Multiple Entries ............................................................................. 23
Extracting Files from Zip Entry to Memory ......................................................................... 24
Reading a Zipped File Using a StreamReader...................................................................... 25
Retrieving Images from a Zip File ....................................................................................... 26
Saving a String Variable to a Zip File ................................................................................... 29
Setting the Level of Compression ....................................................................................... 31
Using Passwords to Protect Zip Files .................................................................................. 31
Zip for .NET Tutorials ............................................................................................................. 33
Compressing Data in Memory ............................................................................................ 34
Compressing Files .............................................................................................................. 45
Compressed Serialization ................................................................................................... 55
Handling Zip Files ............................................................................................................... 65
Zip for .NET Frequently Asked Questions ............................................................................... 82
API Reference ........................................................................................................................ 82
C1.C1Zip.4 Assembly.......................................................................................................... 82
Namespaces .................................................................................................................. 82
C1.C1Zip Namespace.................................................................................................. 82
Overview................................................................................................................ 82

Classes ................................................................................................................... 84
C1ZipEntry.......................................................................................................... 84
Overview ........................................................................................................ 84
Members ........................................................................................................ 85
Methods ......................................................................................................... 87
CheckCRC32 Method .................................................................................. 87
CheckPassword Method ............................................................................. 88
Extract Method........................................................................................... 89
OpenReader Method .................................................................................. 90
Remove Method ......................................................................................... 90
Properties ....................................................................................................... 91
Attributes Property ..................................................................................... 92
Comment Property ..................................................................................... 92
CRC32 Property .......................................................................................... 93
Date Property ............................................................................................. 93
FileName Property ...................................................................................... 94
IsEncrypted Property .................................................................................. 95
SizeCompressed Property ........................................................................... 95
SizeCompressedLong Property .................................................................... 96
SizeUncompressed Property ....................................................................... 96
SizeUncompressedLong Property ................................................................ 97
C1ZipEntryCollection .......................................................................................... 98
Overview ........................................................................................................ 98
Members ........................................................................................................ 99
Methods ........................................................................................................100
Add Method ..............................................................................................101
Add(String) Method ...............................................................................102
Add(String[]) Method .............................................................................102
Add(String,Int32) Method ......................................................................103
Add(String,String) Method .....................................................................104
Add(String,String,DateTime) Method .....................................................106
Add(Stream,String) Method ...................................................................107
Add(Stream,String,DateTime) Method ...................................................108
AddFolder Method ....................................................................................109

AddFolder(String) Method .....................................................................109


AddFolder(String,String) Method ...........................................................110
AddFolder(String,String,Boolean) Method ..............................................111
Contains Method .......................................................................................113
Contains(String) Method ........................................................................113
Contains(C1ZipEntry) Method ................................................................114
Extract Method..........................................................................................115
Extract(Int32,String) Method..................................................................115
Extract(String,String) Method.................................................................116
Extract(Int32) Method............................................................................117
Extract(String) Method...........................................................................118
ExtractFolder Method ................................................................................119
IndexOf Method ........................................................................................120
IndexOf(String) Method .........................................................................121
IndexOf(C1ZipEntry) Method .................................................................121
OpenWriter Method ..................................................................................122
OpenWriter(String,Boolean) Method .....................................................123
OpenWriter(String,DateTime,Boolean) Method .....................................124
Remove Method ........................................................................................125
Remove(Int32) Method ..........................................................................126
Remove(String) Method .........................................................................127
Remove(Int32[]) Method .......................................................................127
Remove(String[]) Method ......................................................................128
Properties ......................................................................................................129
Count Property ..........................................................................................129
Item Property ............................................................................................130
Item(Int32) Property ..............................................................................131
Item(String) Property .............................................................................131
C1ZipFile............................................................................................................132
Overview .......................................................................................................134
Members .......................................................................................................135
C1ZipFile Constructor ....................................................................................137
C1ZipFile Constructor() ..............................................................................138
C1ZipFile Constructor(String,Boolean)........................................................139

C1ZipFile Constructor(String) .....................................................................140


C1ZipFile Constructor(Stream,Boolean) .....................................................141
C1ZipFile Constructor(Stream) ...................................................................142
Methods ........................................................................................................142
Close Method ............................................................................................143
CloseBatch Method ...................................................................................144
Create Method ..........................................................................................145
Create(String) Method ...........................................................................145
Create(Stream) Method .........................................................................146
IsZipFile Method ........................................................................................147
IsZipFile(String) Method .........................................................................148
IsZipFile(Stream) Method .......................................................................149
Open Method ............................................................................................149
Open(String) Method .............................................................................150
Open(Stream) Method ...........................................................................151
OpenBatch Method ...................................................................................153
Refresh Method.........................................................................................154
Properties ......................................................................................................154
Comment Property ....................................................................................156
CompressionLevel Property .......................................................................156
Entries Property .........................................................................................157
FileName Property .....................................................................................157
MemoryThreshold Property.......................................................................158
OverwriteHidden Property .........................................................................159
OverwriteReadOnly Property .....................................................................159
OverwriteSystem Property.........................................................................160
Password Property.....................................................................................160
TempFileName Property ............................................................................173
UseUtf8Encoding Property.........................................................................173
Events............................................................................................................174
Progress Event ...........................................................................................175
C1ZStreamReader..............................................................................................175
Overview .......................................................................................................177
Members .......................................................................................................178

C1ZStreamReader Constructor.......................................................................181
C1ZStreamReader Constructor(Stream) .....................................................182
C1ZStreamReader Constructor(Stream,Boolean,Int32)...............................183
C1ZStreamReader Constructor(Stream,Boolean)........................................184
C1ZStreamReader Constructor(Stream,Boolean,Boolean) ..........................185
C1ZStreamReader Constructor(Stream,Boolean,Int32,Int32) .....................186
C1ZStreamReader Constructor(Stream,Boolean,Int64,Int32) .....................188
Methods ........................................................................................................189
Close Method ............................................................................................190
Flush Method ............................................................................................191
Read Method.............................................................................................192
ReadByte Method ......................................................................................193
Seek Method .............................................................................................194
SetLength Method .....................................................................................194
Write Method ............................................................................................195
Properties ......................................................................................................196
BaseStream Property .................................................................................197
CanRead Property ......................................................................................198
CanSeek Property ......................................................................................198
CanWrite Property .....................................................................................199
Length Property .........................................................................................200
OwnsBaseStream Property ........................................................................200
Position Property .......................................................................................201
SizeCompressed Property ..........................................................................201
SizeCompressedLong Property ...................................................................202
SizeUncompressed Property ......................................................................202
SizeUncompressedLong Property ...............................................................203
ZStream Property.......................................................................................203
C1ZStreamWriter...............................................................................................204
Overview .......................................................................................................206
Members .......................................................................................................207
C1ZStreamWriter Constructor........................................................................210
C1ZStreamWriter Constructor(Stream) ......................................................211
C1ZStreamWriter Constructor(Stream,Boolean).........................................212

C1ZStreamWriter Constructor(Stream,Boolean,Boolean) ...........................213


C1ZStreamWriter Constructor(Stream,CompressionLevelEnum) ................214
C1ZStreamWriter Constructor(Stream,CompressionLevelEnum,Boolean) ..215
C1ZStreamWriter
Constructor(Stream,CompressionLevelEnum,Boolean,Boolean).................216
Methods ........................................................................................................218
Close Method ............................................................................................219
Flush Method ............................................................................................220
Read Method.............................................................................................220
Seek Method .............................................................................................221
SetLength Method .....................................................................................222
Write Method ............................................................................................223
WriteByte Method .....................................................................................224
Properties ......................................................................................................225
BaseStream Property .................................................................................226
CanRead Property ......................................................................................227
CanSeek Property ......................................................................................227
CanWrite Property .....................................................................................228
Checksum Property....................................................................................228
Length Property .........................................................................................229
OwnsBaseStream Property ........................................................................230
Position Property .......................................................................................230
SizeCompressed Property ..........................................................................231
SizeCompressedLong Property ...................................................................231
SizeUncompressed Property ......................................................................232
SizeUncompressedLong Property ...............................................................232
ZStream Property.......................................................................................233
ZipFileException ................................................................................................234
Overview .......................................................................................................235
Members .......................................................................................................235
ZipFileException Constructor .........................................................................237
ZipFileException Constructor(String) ..........................................................237
ZipFileException Constructor(String,String) ................................................238
ZipFileException Constructor(String,String,Exception) ................................239

ZipProgressEventArgs ........................................................................................240
Overview .......................................................................................................241
Members .......................................................................................................242
Properties ......................................................................................................243
Cancel Property .........................................................................................243
FileLength Property....................................................................................244
FileLengthLong Property ............................................................................244
FileName Property .....................................................................................245
Position Property .......................................................................................245
PositionLong Property................................................................................246
Enumerations ........................................................................................................246
CompressionLevelEnum ....................................................................................246
Delegates ..............................................................................................................247
ZipProgressEventHandler ..................................................................................247
C1.C1Zip.ZLib Namespace .........................................................................................248
Overview...............................................................................................................248
Classes ..................................................................................................................249
ZStream.............................................................................................................249
Overview .......................................................................................................250
Members .......................................................................................................251
ZStream Constructor......................................................................................254
ZStream Constructor() ...............................................................................254
ZStream Constructor(Boolean)...................................................................255
Methods ........................................................................................................256
deflate Method..........................................................................................257
deflateEnd Method ....................................................................................258
deflateInit Method.....................................................................................259
deflateInit(Int32) Method ......................................................................259
deflateInit(Int32,Int32) Method .............................................................260
deflateParams Method ..............................................................................262
deflateSetDictionary Method .....................................................................262
inflate Method...........................................................................................264
inflateEnd Method .....................................................................................265
inflateInit Method......................................................................................266

inflateInit() Method ...............................................................................266


inflateInit(Int32) Method .......................................................................267
inflateSetDictionary Method ......................................................................268
inflateSync Method....................................................................................269
Fields .............................................................................................................270
adler Field..................................................................................................271
avail_in Field..............................................................................................272
avail_out Field ...........................................................................................273
msg Field ...................................................................................................273
next_in Field ..............................................................................................274
next_in_index Field ....................................................................................274
next_out Field............................................................................................275
next_out_index Field .................................................................................275
total_in Field..............................................................................................276
total_out Field ...........................................................................................276
Z_BUF_ERROR Field ...................................................................................277
Z_DATA_ERROR Field .................................................................................278
Z_ERRNO Field ...........................................................................................278
Z_MEM_ERROR Field .................................................................................279
Z_NEED_DICT Field ....................................................................................279
Z_OK Field .................................................................................................280
Z_STREAM_END Field ................................................................................280
Z_STREAM_ERROR Field ............................................................................281
Z_VERSION_ERROR Field............................................................................281
ZStreamException .............................................................................................282
Overview .......................................................................................................283
Members .......................................................................................................284

Zip for .NET Overview


Quickly compress data, saving disk space and network bandwidth,
and easily manipulate and work with compressed data. Zip for .NET
allows you to compress files from your applications, including system
and hidden files, and add and delete compressed files and folders;
you can even read and write to zip files stored in streams.

Getting Started
To get started, review
the following topics:

Zip for .NET classes are supported in all .NET development platforms

Key Features

including WinForms, ASP.NET, WPF, Mobile, and a special Silverlight

Zip for .NET


Fundamentals

version exists in Silverlight Edition.

Samples

See Also
Help with WinForms Edition
Creating a Mobile Device Application
Migrating a Zip for .NET Project to Visual Studio 2005

Help with WinForms Edition


Getting Started
For information on installing ComponentOne Studio WinForms Edition, licensing, technical
support, namespaces and creating a project with the control, please visit Getting Started with
WinForms Edition.

Creating a Mobile Device Application


To create a new .NET 2.0 device application project, complete the following steps:
1.
2.
3.

From the File menu in Microsoft Visual Studio .NET, select New | Project. The New
Project dialog box opens.
Under Project Types, expand the Visual Basic or Visual C# node. Note that one of
these options may be located under Other Languages.
Expand the Smart Device node and select one of the smart devices listed.

4.

Select Device Application from the list of Templates in the right pane.

5.

Enter a name in the Name textbox and click OK. A new project is created, and a new
Form1 is displayed in the Designer view.
Reference the C1Zip assembly in your project.

6.

Migrating a Zip for .NET Project to Visual


Studio 2005
To migrate a project using ComponentOne components to Visual Studio 2005, there are two
main steps that must be performed. First, you must convert your project to Visual Studio 2005,
which includes removing any references to a previous assembly and adding a reference to the
new assembly. Second, you must update the project References to use the new C1.C1Zip.2.dll.

To convert the project:


1.
2.
3.
4.
5.
6.
7.
8.

Open Visual Studio 2005 and select File | Open | Project/Solution.


Locate the .sln file for the project that you wish to convert to Visual Studio 2005. Select
it and click Open. The Visual Studio Conversion Wizard appears.
Click Next.
Select Yes, create a backup before converting to create a backup of your current
project and click Next.
Click Finish to convert your project to Visual Studio 2005. The Conversion Complete
window appears.
Click Show the conversion log when the wizard is closed if you want to view the
conversion log.
Click Close. The project opens. Now you must remove references to any of the previous
ComponentOne .dlls and add references to the new ones.
Go to the Solution Explorer (View | Solution Explorer), select the project, and click the
Show All Files button.
Note: The Show All Files button does not appear in the Solution Explorer toolbar if the
Solution project node is selected.

9. Expand the References node, right-click C1.C1Zip and select Remove.


10. Right-click the References node and select Add Reference.
11. Locate and select C1.C1Zip.2.dll. Click OK to add it to the project.

Key Features
Some of the main features of Zip for .NET that you may find useful include the following:

Major operations
With Zip for .NET, you can:

o Obtain global information on a zip file.


o Obtain a detailed list of a zip file's contents via a collection object.
o Delete files from within a zip file.
o Test the integrity of a zip file and its contents.
o Add and retrieve comments for individual files in the zip file.
o Get and set the global zip file comment.
o Control what path information is stored in the zip file for each file.
o Zip system and hidden files.
o Control the amount of compression applied to files being zipped.
o Specify the path where files will be uncompressed to.
o Work on temporary copies of zip files, for maximum safety.
Compress and Expand Folders
With Zip you can easily compress and expand folders while preserving folder structure.

Read and Write to Streams


Zip can read and write to zip files stored in streams in addition to actual files using the
C1ZipFile.Open(Stream) method. This allows reading zip files embedded in application
resources or stored in database fields instead of in actual files.

Get and Set File Information


Easily obtain zip file information including a detailed list of the zip file's contents. You
can also control file information by adding and retrieving comments and control path
information for individual entries in the zip file, and getting and setting the global zip
file comment.

File Integrity and Safety


With Zip you can test the integrity of a zip file and its contents and work on temporary
copies of zip files to ensure maximum safety.

Compress and Manipulate Compressed Files


Compress files, including system and hidden files, and easily manipulate compressed
files by deleting files from within a zip file, controlling the amount of compression
applied to files being zipped, and specifying the path where files will be uncompressed
to.

Incorporates the ZLIB Advantage


ZLIB is a general-purpose, lossless data-compression library with a portable, crossplatform data format. Unlike Unix compress and GIF image format LZW compression,
the ZLIB compression method essentially never expands the data (LZW doubles or
triples the file size in extreme cases) and has a memory footprint independent of input
data.

Support for Zip64


C1Zip now supports Zip64 files. This allows for entries longer than the usual 4 gig limit
and also allows more entries per zip file. The maximum number of entries per ZIP file is
2,147,483,647 (int.MaxValue). The maximum uncompressed entry size is
9,223,372,036,854,775,807 (long.MaxValue).

Fast, low memory usage compression engine


The low memory compression engine lets you:

o Zip files or memory buffers into new or existing zip files.


o Unzip files to disk or directly to memory.
o Compress and decompress strings or buffers completely in memory.
o Stream-based compression and decompression for maximum flexibility.
100% managed C# code
C1.C1Zip.ZLib is a C# implementation of Adler and Gailly's ZLIB code and contains a
main class ZStream that handles stream-based compression and decompression. ZLIB
handles the actual data compression and decompression.
ZLIB is designed to be a free, general-purpose, lossless data-compression library for use
on virtually any computer hardware and operating system. The ZLIB data format is itself
portable across platforms. Unlike the LZW compression method used in Unix compress
and in the GIF image format, the compression method currently used in ZLIB essentially
never expands the data. (LZW can double or triple the file size in extreme cases.) ZLIB's
memory footprint is also independent of the input data.

Simple, intuitive object model


Zip for .NET contains three main classes:

C1ZStreamWriter is a stream object that takes regular data on input, compresses it, and
writes it out to an underlying stream. You can compress data to files, memory, or any
other type of stream. You can attach a BinaryWriter object to C1ZStreamWriter to
write objects directly, without dealing with byte arrays.
C1ZStreamReader is a stream object that takes a compressed stream as input and
decompresses it as it reads data from the underlying compressed stream. You can
attach a BinaryReader object to C1ZStreamReader to read objects directly, without
dealing with byte arrays.

C1ZipFile is a class that deals with zip files. It allows you to create, open, and modify zip
files. C1ZipFile has a Entries property that represents a collection of entries in a zip file.

Zip for .NET Fundamentals


The classes in the C1Zip library are divided into three levels:
Level

Main Classes

Description

High

C1ZipFile, C1ZipEntry,

Use these classes to create, open, and manage ZIP files.

C1ZipEntryCollection

You can inspect the contents of ZIP files, test their


integrity, add, delete, and extract entries to and from ZIP
files.

Medium C1ZStreamReader,
C1ZStreamWriter

Use these classes to compress and expand data into and


out of regular .NET streams (including memory, file, and
network streams).

Low

ZStream

This is the lowest level class in C1Zip. It is a 100% C#


implementation of Zlib, the popular data-compression
library written by Jean-loup Gailly and Mark Adler. ZStream
is used by the higher level classes in C1Zip.

See Also
High Level: C1ZipFile, C1ZipEntry and C1ZipEntryCollection Classes
Medium Level: C1ZStreamReader and C1ZStreamWriter Classes
Low Level: ZStream Class

High Level: C1ZipFile, C1ZipEntry and


C1ZipEntryCollection Classes
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:

You can consolidate many files into one, making application deployment easier.
You can compress the data, saving disk space and network bandwidth.
The zip format is an open standard, supported by many popular applications.

C1ZipFile Class

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");

C1ZipEntryCollection Class
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);

C1ZipEntry Class
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.

Medium Level: C1ZStreamReader and


C1ZStreamWriter Classes
The C1ZStreamReader and C1ZStreamWriter classes allow you to use data compression on any
.NET streams, not only in zip files.
To use C1ZStreamReader and C1ZStreamWriter objects, attach them to regular streams and
read or write the data through them. The data is compressed (or expanded) on the fly into (or
out of) the underlying stream.
This design allows great integration with native .NET streams. The diagram below illustrates how
it works:

For example, the code below saves an ADO.NET DataTable object into a stream and then reads
it back:
To write code in Visual Basic
Visual Basic

Copy Code

' Save the DataTable into a compressed stream.


Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
Dim fout As New FileStream("test.tmp", FileMode.Create)
bf.Serialize(fout, DataTableOut)
fout.Close()
' Read the compressed data.
Dim fin As New FileStream("test.tmp", FileMode.Open)
Dim DataTableIn As DataTable = bf.Deserialize(fin)
To write code in C#
C#

Copy Code

// Save the DataTable into compressed stream.


System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
FileStream fout = new FileStream("test.tmp", FileMode.Create);
bf.Serialize(fout, DataTableOut);
fout.Close();
// Read the compressed data.
FileStream fin = new FileStream("test.tmp", FileMode.Open);
DataTable DataTableIn = (DataTable)bf.Deserialize(fin);
To add data compression, you would simply add two lines of code:
To write code in Visual Basic
Visual Basic

Copy Code

' Save the DataTable into a compressed stream.


Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
Dim fout As New FileStream("test.tmp", FileMode.Create)
Dim compressor As New C1ZStreamWriter(fout)
bf.Serialize(compressor, DataTableOut)

fout.Close()
' Read the compressed data.
Dim fin As New FileStream("test.tmp", FileMode.Open)
Dim decompressor As New C1ZStreamReader(fin)
Dim DataTableIn As DataTable = bf.Deserialize(decompressor)

To write code in C#
C#

Copy Code

// Save the DataTable into a compressed stream.


System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
FileStream fout = new FileStream("test.tmp", FileMode.Create);
C1ZStreamWriter compressor = new C1ZStreamWriter(fout);
bf.Serialize(compressor, DataTableOut);
fout.Close();
// Read compressed data.
FileStream fin = new FileStream("test.tmp", FileMode.Open);
C1ZStreamReader decompressor = new C1ZStreamReader(fin);
DataTable DataTableIn = (DataTable)bf.Deserialize(decompressor);

Low Level: ZStream Class


This is the lowest-level class in the C1Zip library, and it is used extensively by the higher-level
classes described above.
Most users will never need to use ZStream directly. It is the most flexible, but the hardest to use
component in the C1Zip library. ZStream is a C# implementation of the ZLIB library. ZLIB is an
open-source library written by Jean-loup Gailly and Mark Adler.
For more information on ZLIB, check http://www.info-zip.org/ or http://www.gzip.org/.

Zip for Mobile Devices Fundamentals


The mobile version of Zip for .NET allows you to quickly develop Microsoft.NET Compact
Framework-based applications for your mobile devices, such as personal digital assistants
(PDA's), mobile phones, and more. It implements several classes that allow you to add data
compression to your applications.

Zip for Mobile supports all members of the object model that are supported by the .NET
Compact Framework.
Note that the code examples provided in this documentation are examples for using Zip for
.NET. If you would like to see samples for the mobile version, they are installed with Zip for
Mobile Devices, or you can get them online at
http://helpcentral.componentone.com/Samples.aspx.

Zip for .NET Samples


Please be advised that this ComponentOne software tool is accompanied by various sample
projects and/or demos, which may make use of other development tools included with
ComponentOne Studio Enterprise.
Please refer to the pre-installed product samples through the following path:

Documents\ComponentOne Samples\WinForms
Click one of the following links to view a list of C1Zip samples:
Visual Basic Samples
Sample

Description

Files

Shows how to compress and expand individual files. This sample calls the
C1.C1Zip namespace.

Memory

Shows how to compress and expand memory streams. This sample calls the
C1.C1Zip namespace.

Serialization

Shows how to add compression to the .NET serialization support. This sample
calls the C1.C1Zip namespace.

ZipFileDemo Shows how to implement a simple zip utility. This sample uses the C1.C1Zip
namespace.
ZipFileSimple Shows how to implement a simple zip utility. This sample lets you create, open,
and edit standard zip files. Note that this is a stripped-down version of the
ZipFileDemo sample.

C# Samples

Sample

Description

Files

Shows how to compress and expand individual files. This sample calls
the C1.C1Zip namespace.

InMemoryCompression Shows how to create and use an in-memory archive. This sample calls
the C1.C1Zip namespace.
Memory

Shows how to compress and expand memory streams. This sample


calls the C1.C1Zip namespace.

SelfExtract

Self-extracting application. This sample calls the C1.C1Zip namespace.

Serialization

Shows how to add compression to the .NET serialization support. This


sample calls the C1.C1Zip namespace.

ZipFileDemo

Shows how to implement a simple zip utility. This sample uses the
C1.C1Zip namespace.

ZipImages

Shows how to retrieve images directly from a zip file. This sample calls
the C1.C1Zip namespace.

Zip for Mobile Devices Samples (Visual Basic and C#)


Sample

Description

DataSet

Add compression to the .NET serialization support. This sample calls the
C1.C1Zip namespace.

LongString Compress and expand strings. This sample calls the C1.C1Zip namespace.
ZipFile

Implement a simple zip utility. This sample calls the C1.C1Zip namespace.

Zip for .NET Task-Based Help


The task-based help section assumes that you are familiar with programming in the Visual
Studio environment. If you are a novice to C1Zip, see the Zip for .NET Tutorials first.

Each task-based help topic provides a solution for specific tasks referencing the C1.C1Zip
namespace. Each topic also assumes that you have created a new .NET project.

See Also
Compressing Datasets
Compressing an Entire Folder into a Zip File
Creating a Zip File with Multiple Entries
Extracting Files from Zip Entry to Memory
Reading a Zipped File Using a StreamReader
Retrieving Images from a Zip File
Saving a String Variable to a Zip File
Setting the Level of Compression
Using Passwords to Protect Zip Files

Compressing Datasets
To write a dataset into a compressed zip file, use the following code:
To write code in Visual Basic
Visual Basic

Copy Code

Private Sub SaveDataSet(ds As DataSet)


' Open/create zip file.
Dim zip As New C1.C1Zip.C1ZipFile()
zip.Open("c:\temp\dataset.zip")
' Write the dataset into the zip file.
Dim s As Stream = zip.Entries.OpenWriter(ds.DataSetName, True)
Try
ds.WriteXml(s, XmlWriteMode.WriteSchema)
Finally
s.Dispose()
End Try
End Sub
Private Sub CheckDataSet(ds As DataSet)
' Open/create zip file.
Dim zip As New C1.C1Zip.C1ZipFile()

zip.Open("c:\temp\dataset.zip")
' Read the dataset from the zip file.
Dim dsTest As New DataSet(ds.DataSetName) '
Dim s As Stream = zip.Entries(ds.DataSetName).OpenReader()
Try
dsTest.ReadXml(s)
Finally
s.Dispose()
End Try
' Check that the datasets are equivalent.
Dim i As Integer
For i = 0 To ds.Tables.Count - 1
Dim dt1 As DataTable = ds.Tables(i)
Dim dt2 As DataTable = dsTest.Tables(i)
Debug.Assert((dt1.TableName = dt2.TableName And dt1.Columns.Count =
dt2.Columns.Count And dt1.Rows.Count = dt2.Rows.Count))
Next i
End Sub
To write code in C#
C#

Copy Code

private void SaveDataSet(DataSet ds)


{
// Open/create zip file.
C1.C1Zip.C1ZipFile zip = new C1.C1Zip.C1ZipFile();
zip.Open(@"c:\temp\dataset.zip");
// Write the dataset into the zip file.
using (Stream s = zip.Entries.OpenWriter(ds.DataSetName, true))
{
ds.WriteXml(s, XmlWriteMode.WriteSchema);
}
}
private void CheckDataSet(DataSet ds)
{
// Open/create zip file.
C1.C1Zip.C1ZipFile zip = new C1.C1Zip.C1ZipFile();
zip.Open(@"c:\temp\dataset.zip");

// Read the dataset from the zip file.


DataSet dsTest = new DataSet(ds.DataSetName);
using (Stream s = zip.Entries[ds.DataSetName].OpenReader())
{
dsTest.ReadXml(s);
}
// Check that the datasets are equivalent.
for (int i = 0; i < ds.Tables.Count; i++)
{
DataTable dt1 = ds.Tables[i];
DataTable dt2 = dsTest.Tables[i];
System.Diagnostics.Debug.Assert(dt1.TableName == dt2.TableName &&
dt1.Columns.Count == dt2.Columns.Count && dt1.Rows.Count == dt2.Rows.Count);
}
}

Compressing an Entire Folder into a Zip


File
To compress an entire folder into a zip file, preserving the folder structure for later expansion,
use the AddFolder method.
For example, to compress the contents of the "c:\temp" folder, including all subfolders, use the
following code:
To write code in Visual Basic
Visual Basic

Copy Code

C1Zip.Entries.AddFolder("c:\temp\", "*.*", True)


To write code in C#
C#

Copy Code

C1Zip.Entries.AddFolder(@"c:\temp\", "*.*", true);


To extract the folder later, including the original folder structure, use the following code:

To write code in Visual Basic


Visual Basic

Copy Code

C1Zip.Entries.ExtractFolder("c:\temp\")
To write code in C#
C#

Copy Code

C1Zip.Entries.ExtractFolder(@"c:\temp\");

Creating a Zip File with Multiple Entries


To stream multiple XML files directly into the zip file, use the OpenWriter method. That returns
a stream that you can write to, and when the stream is closed it is added to the zip file.
Add the following code to the Click event:
To write code in Visual Basic
Visual Basic

Copy Code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim zip As New C1ZipFile()
zip.Create("c:\temp\test.zip")
Dim s As Stream = zip.Entries.OpenWriter("entry1", True)
Dim sw As New StreamWriter(s)
sw.WriteLine("Hello world")
' Continue writing as much as you want...
sw.Close()
s = zip.Entries.OpenWriter("entry2", True)
sw = New StreamWriter(s)
sw.WriteLine("Hello again")
' Continue writing as much as you want...
sw.Close()
End Sub

To write code in C#
C#

Copy Code

private void button1_Click(object sender, System.EventArgs e)


{
C1ZipFile zip = new C1ZipFile();
zip.Create(@"c:\temp\test.zip");
Stream s = zip.Entries.OpenWriter("entry1", true);
StreamWriter sw = new StreamWriter(s);
sw.WriteLine("Hello world");
// Continue writing as much as you want...
sw.Close();
s = zip.Entries.OpenWriter("entry2", true);
sw = new StreamWriter(s);
sw.WriteLine("Hello again");
// Continue writing as much as you want...
sw.Close();
}
To read an entry without saving it to a file, use the OpenReader method on the entry object.
Note: OpenWriter is a member of the C1ZipEntryCollection class, while OpenReader is a
member of the C1ZipEntry class.

Extracting Files from Zip Entry to Memory


Gets or sets the text of the caption of the "Text" column in the result list.

Syntax
Visual Basic (Declaration)
Public Property TextCaptionText As System.String
C#
public System.string TextCaptionText {get; set;}

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1PreviewTextSearchPanel Class
C1PreviewTextSearchPanel Members

Reading a Zipped File Using a


StreamReader
To read a zipped file using a StreamReader, add the following code:
To write code in Visual Basic
Visual Basic

Copy Code

' Open a zip file.


Dim zip As New C1ZipFile()
zip.Open("c:\temp\myzipfile.zip")
' Open an input stream on any entry.
Dim ze As C1ZipEntry = zip.Entries("someFile.cs")
Dim s As Stream = ze.OpenReader()
' Open the StreamReader on the stream.
Dim sr As New StreamReader(s)
' Use the StreamReader, then close it.
To write code in C#
C#

Copy Code

// Open a zip file.


C1ZipFile zip = new C1ZipFile();
zip.Open(@"c:\temp\myzipfile.zip");
// Open an input stream on any entry.
C1ZipEntry ze = zip.Entries["someFile.cs"];
Stream s = ze.OpenReader();

// Open the StreamReader on the stream.


StreamReader sr = new StreamReader(s);
// Use the StreamReader, then close it.

Retrieving Images from a Zip File


To retrieve images directly from a zip file, first add the following code to the Form_Load event
to compress several image files into a zip file:
To write code in Visual Basic
Visual Basic

Copy Code

' Build a list of images in resource directory, and add them all to a zip
file.
Dim zip As New C1ZipFile()
Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
' Get the application directory.
Dim s As String = Application.ExecutablePath
s = s.Substring(0, s.IndexOf("\bin")) + "\resources"
' Create the zip file.
zip.Create((s + "\images.zip"))
' Populate the zip file and list.
Dim f As String
For Each f In

Directory.GetFiles(s)

Dim fname As String = f.ToLower()


' Skip self.
If fname.EndsWith("zip") Then
GoTo ContinueForEach1
End If
' Add to the list.
ListBox1.Items.Add(Path.GetFileName(fname))
' Add to the zip file.
zip.Entries.Add(fname)
ContinueForEach1:
Next f
End Sub

To write code in C#
C#

Copy Code

// Build a list of images in resource directory, and add them all to a zip
file.
C1ZipFile zip = new C1ZipFile();
private void Form1_Load(object sender, System.EventArgs e)
{
// Get the application directory.
string s = Application.ExecutablePath;
s = s.Substring(0, s.IndexOf(@"\bin")) + @"\resources";
// Create the zip file.
zip.Create(s + @"\images.zip");
// Populate the zip file and list.
foreach (string f in Directory.GetFiles(s))
{
string fname = f.ToLower();
// Skip self.
if (fname.EndsWith("zip")) continue;
// Add to the list.
listBox1.Items.Add(Path.GetFileName(fname));
// Add to the zip file.
zip.Entries.Add(fname);
}
}
To allow you to select an image, retrieve a stream with the image data (OpenReader method),
and load the image (Image.FromStream method), add the following code to the
SelectedIndexChanged event:
To write code in Visual Basic
Visual Basic

Copy Code

' Show selected image.


Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
' Get the selected item.
Dim item As String = CStr(listBox1.SelectedItem)
' Load the image directly from a compressed stream.
Dim s As Stream = zip.Entries(item).OpenReader()
Try
pictureBox1.Image = CType(Image.FromStream(s), Image)
Catch
End Try
' Done with stream.
s.Close()
End Sub
To write code in C#
C#

Copy Code

// Show selected image.


private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
// Get the selected item.
string item = (string)listBox1.SelectedItem;
// Load the image directly from a compressed stream.
Stream s = zip.Entries[item].OpenReader();
try
{
pictureBox1.Image = (Image)Image.FromStream(s);
}
catch {}
// Done with stream.
s.Close();
}
This topic illustrates the following:
This example shows several types of images, including ICO, GIF, TIFF, BMP, and JPG images.

Saving a String Variable to a Zip File


To save a string variable to a zip file, use one of the following methods:

C1ZipEntryCollection.OpenWriter method
Use the OpenWriter method to get a stream writer, write the string into it, and then
close it. The data is compressed as you write it into the stream, and the whole stream is
saved into the zip file when you close it.

MemoryStream method
Use a MemoryStream method; write the data into it, and then add the stream to the
zip file. Note that this method requires a little more work than the OpenWriter method,
but is still very manageable.

The following code shows both methods. Add the code to the Button_Click event:
To write code in Visual Basic
Visual Basic

Copy Code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim str As String = "Shall I compare thee to a summer's day? " + "Thou
art more lovely and more temperate. " + "Rough winds do shake the darling

buds of May, " + "And summer's lease hath all too short a date."
Dim zipFile As New C1ZipFile()
zipFile.Create("c:\temp\strings.zip")
' Method 1: OpenWriter.
Dim stream As Stream = zipFile.Entries.OpenWriter("Shakespeare.txt",
True)
Dim sw As New StreamWriter(stream)
sw.Write(str)
sw.Close()
' Method 2: Memory Stream.
stream = New MemoryStream()
sw = New StreamWriter(stream)
sw.Write(str)
sw.Flush()
stream.Position = 0
zipFile.Entries.Add(stream, "Shakespeare2.txt")
stream.Close()
End Sub
To write code in C#
C#

Copy Code

private void button1_Click(object sender, System.EventArgs e)


{
string str = "Shall I compare thee to a summer's day? " +
"Thou art more lovely and more temperate. " +
"Rough winds do shake the darling buds of May, " +
"And summer's lease hath all too short a date.";
C1ZipFile zipFile = new C1ZipFile();
zipFile.Create(@"c:\temp\strings.zip");
// Method 1: OpenWriter.
Stream stream = zipFile.Entries.OpenWriter("Shakespeare.txt", true);
StreamWriter sw = new StreamWriter(stream);
sw.Write(str);
sw.Close();
// Method 2: Memory Stream.
stream = new MemoryStream();
sw = new StreamWriter(stream);
sw.Write(str);
sw.Flush();

stream.Position = 0;
zipFile.Entries.Add(stream, "Shakespeare2.txt");
stream.Close();
}

Setting the Level of Compression


To minimize the file size of the compressed file, set the compression level on the
C1ZStreamWriter's constructor by using the following code:
To write code in Visual Basic
Visual Basic

Copy Code

Dim fn As String = Path.GetTempFileName()


Dim fs As New FileStream(fn, FileMode.Create)
Dim compressor As New C1ZStreamWriter(fs,
CompressionLevelEnum.BestCompression)
To write code in C#
C#

Copy Code

string fn = Path.GetTempFileName();
FileStream fs = new FileStream(fn, FileMode.Create);
C1ZStreamWriter compressor = new
C1ZStreamWriter(fs,CompressionLevelEnum.BestCompression);
Note that the code sample above sets the compression level to BestCompression, which has
the highest compression time and the lowest speed. Other compression level options on the
C1ZStreamWriter's constructor include the following:

BestSpeed has low compression time and the highest speed.


DefaultCompression has normal compression time and speed.
NoCompression has no compression.

Using Passwords to Protect Zip Files


To create password-protected zip files, set the Password property to a non-empty string before
creating any entries. Each entry may have its own password. For example:
To write code in Visual Basic

Visual Basic

Copy Code

C1Zip.Password = "password"
C1Zip.Entries.Add(someFile)
To write code in C#
C#

Copy Code

C1Zip.Password = "password";
C1Zip.Entries.Add(someFile);
To extract this entry later, the Password property must be set to the same value in effect when
the entry was added. For example:
To write code in Visual Basic
Visual Basic

Copy Code

' Will fail, password not set.


C1Zip.Password = ""
C1Zip.Entries.Extract(someFile)
' Will fail, wrong password.
C1Zip.Password = "pass"
C1Zip.Entries.Extract(someFile)
' Will succeed.
C1Zip.Password = "password"
C1Zip.Entries.Extract(someFile)
To write code in C#
C#

Copy Code

// Will fail, password not set.


C1Zip.Password = "";
C1Zip.Entries.Extract(someFile);
// Will fail, wrong password.
C1Zip.Password = "pass";
C1Zip.Entries.Extract(someFile);

// Will succeed.
C1Zip.Password = "password";
C1Zip.Entries.Extract(someFile);

Zip for .NET Tutorials


The following topics contain tutorials that illustrate some of the main features in the C1Zip
library. The tutorials walk you through the creation of several simple projects, describing each
step in detail. See the included Zip for .NET Samples for additional examples that can be used as
a reference.
Tutorial

Description

Compressing

Shows how you can compress and expand arbitrary data in memory. This

Data in Memory

technique is useful in any situation where you keep memory streams while
the application is running. By compressing the streams, you can reduce the
memory requirements for your application.

Compressing

Shows how you can compress individual files so they take up less disk space

Files

and are less exposed to access by users. Note that these are not zip files, just
individual compressed files. The last tutorial covers zip files.

Compressed

Shows how you can combine Zip with .NET serialization to save objects into

Serialization

streams that are a fraction of the regular size. If you are serializing objects
into XML streams, the savings in disk space and network bandwidth can be
huge.

Handling Zip

Shows how you can open, inspect, add, and remove files in a zip archive.

Files

Using the zip format for your application storage needs has several
advantages: it is an open-standard, well-documented, space-efficient format.

See Also
Compressing Data in Memory
Compressing Files
Compressed Serialization
Handling Zip Files

Compressing Data in Memory


This tutorial shows how you can compress basic data types such as strings and doubles into
memory streams, and expand the data back when you read it from the streams. Here is what
the final application will look like:

Step 1: Create the main form.


Start a new Visual Studio project. From the Toolbox, add the following controls to the form, by
performing a drag-and-drop operation or by double-clicking the component:

Four Button controls along the left edge of the form, as shown in the picture above. In
the Properties window make the following changes to each Button control:
Button

Button.Text Property

Button.Name Property

Button.Enabled Property

Compress String

btnCompressString

True (Default)

Decompress String

btnExpandString

False

Compress Data

btnCompressData

True (Default)

Decompress Data

btnExpandData

False

Note: The Decompress String and Decompress Data buttons cannot be used until we
have some compressed data to expand.

A TextBox on the upper-right of the form. Set the MultiLine property to True. Select
the ellipsis button located next to Lines property. In the String Collection Editor
dialog box type text to use as an initial value.

A Label control below the text box.

Step 2: Add a reference to the C1Zip assembly.


Go to the Solution Explorer window and click the Show All Files button. Right-click on
References, and select the Add Reference menu option. Select the C1.C1Zip assembly from
the list, or browse to find the C1.C1Zip.2.dll file.
Select the Form1.vb tab (Form1.cs for C#) or go to View|Code to open the Code Editor. At the
top of the file, add the following statements:
To write code in Visual Basic
Visual Basic

Copy Code

Imports System.IO
Imports C1.C1Zip
To write code in C#
C#

using System.IO;
using C1.C1Zip;

Copy Code

This makes the objects defined in the C1Zip assembly visible to the project and saves a lot of
typing.

Step 3: Add code to compress strings.


Double-click the Compress String command button, and add the following code to handle the
btnCompressString_Click event:
To write code in Visual Basic
Visual Basic

Copy Code

Private m_CompressedString As Byte()


Private Sub btnCompressString_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCompressString.Click
' Compress the string.
Dim ticks As Long = DateTime.Now.Ticks
m_CompressedString = CompressString(textBox1.Text)
' Tell the user how long it took.
Dim ms As Integer
ms = (DateTime.Now.Ticks - ticks) / TimeSpan.TicksPerMillisecond
Dim lenBefore As Integer = textBox1.Text.Length * 2
Dim lenAfter As Integer = m_CompressedString.Length
Dim msg As String
msg = String.Format("Compressed from {0} bytes to " &

"{1} bytes in {2}

milliseconds.", lenBefore, lenAfter, ms)


MessageBox.Show(msg, "Compressed", MessageBoxButtons.OK,
MessageBoxIcon.Information)
' We can now expand it.
btnExpandString.Enabled = True
End Sub
To write code in C#
C#

Copy Code

private byte[] m_CompressedString;


private void btnCompressString_Click(object sender, EventArgs e)
{
// Compress the string.
long ticks = DateTime.Now.Ticks;

m_CompressedString = CompressString(textBox1.Text);
// Tell the user how long it took.
int ms = (int)((DateTime.Now.Ticks - ticks) /
TimeSpan.TicksPerMillisecond);
int lenBefore = textBox1.Text.Length * 2;
int lenAfter = m_CompressedString.Length;
string msg = string .Format("Compressed from {0} bytes to " + "{1} bytes
in {2} milliseconds.", lenBefore, lenAfter, ms);
MessageBox.Show(msg, "Compressed", MessageBoxButtons.OK,
MessageBoxIcon.Information);
// We can now expand it.
btnExpandString.Enabled = true;
}
The first main line declares a member variable called m_CompressedString which will be used
to hold the compressed data (encoded as a byte array). The second main line calls a utility
function CompressString that compresses a given string into a byte array that can later be
expanded to restore the original string. The remainder of the code is used to measure how long
the compression process took and to show a dialog box with statistics.
(Note that the lenBefore variable is calculated as the length of the string times two. This is
because .NET strings are Unicode, and each character actually takes up two bytes.)
Add the following code which implements the CompressString function:
To write code in Visual Basic
Visual Basic

Copy Code

Public Function CompressString(ByVal str As String) As Byte()


' Open the memory stream.
Dim ms As MemoryStream = New MemoryStream()
' Attach a compressor stream to the memory stream.
Dim sw As C1ZStreamWriter = New C1ZStreamWriter(ms)
' Write the data into the compressor stream.
Dim writer As StreamWriter = New StreamWriter(sw)
writer.Write(str)
' Flush any pending data.
writer.Flush()
' Return the memory buffer.
CompressString = ms.ToArray()
End Function

To write code in C#
C#

Copy Code

public byte[] CompressString(string str)


{
// Open the memory stream.
MemoryStream ms = new MemoryStream();
// Attach a compressor stream to the memory stream.
C1ZStreamWriter sw = new C1ZStreamWriter(ms);
// Write the data into the compressor stream.
StreamWriter writer = new StreamWriter(sw);
writer.Write(str);
// Flush any pending data.
writer.Flush();
// Return the memory buffer.
return ms.ToArray();
}
The function starts by creating a new memory stream. This stream will automatically allocate a
memory buffer to hold the compressed data.
Next, the function creates a C1ZStreamWriter object and attaches it to the new memory stream.
Any data written to the C1ZStreamWriter object will be compressed and written to the memory
stream.
The C1ZStreamWriter object only supplies the basic Stream methods for writing bytes and byte
arrays. To be able to write other basic types such as strings, integers, and so on, we attach a
StreamWriter object to the C1ZStreamWriter. Here's a diagram that shows how this works:

After the StreamWriter is set up, all we need to do is call its Write method to write the string
into the compressed memory stream. When done writing, we also call the Flush method to
make sure all cached input is written out.
Finally, the code uses the ToArray method to return the byte array that was created by the
memory stream.

Step 4: Add code to expand strings.


To expand the string, we need to follow the reverse sequence of steps used to compress.
Double-click the Decompress String button, and add the following code to handle the
btnExpandString_Click event:
To write code in Visual Basic
Visual Basic

Copy Code

Private Sub btnExpandString_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnExpandString.Click
' Expand the string.
Dim ticks As Long = DateTime.Now.Ticks
TextBox1.Text = ExpandString(m_CompressedString)
' Tell the user how long it took.
Dim ms As Integer = (DateTime.Now.Ticks - ticks) /
TimeSpan.TicksPerMillisecond
Dim lenBefore As Integer = m_CompressedString.Length
Dim lenAfter As Integer = TextBox1.Text.Length * 2
Dim msg As String
msg = String.Format("Expanded from {0} bytes to {1} bytes " & "in {2}
milliseconds.", lenBefore, lenAfter, ms)
MessageBox.Show(msg, "Expanded", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End Sub
To write code in C#
C#

Copy Code

private void btnExpandString_Click(object sender, EventArgs e)


{

// Expand the string.


long ticks = DateTime.Now.Ticks;
textBox1.Text = ExpandString(m_CompressedString);
// Tell the user how long it took.
int ms = (int)((DateTime.Now.Ticks - ticks) /
TimeSpan.TicksPerMillisecond);
int lenBefore = m_CompressedString.Length;
int lenAfter = textBox1.Text.Length * 2;
string

msg;

msg = string .Format("Expanded from {0} bytes to {1} bytes " + "in {2}
milliseconds.", lenBefore, lenAfter, ms);
MessageBox.Show(msg, "Expanded", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
The main line calls the utility function ExpandString that takes a byte array and returns the
original string. Add the following code for the ExpandString function:
To write code in Visual Basic
Visual Basic

Copy Code

Public Function ExpandString(ByVal buffer As Byte()) As String


' Turn buffer into a memory stream.
Dim ms As MemoryStream = New MemoryStream(buffer)
' Attach a decompressor stream to the memory stream.
Dim sr As C1ZStreamReader = New C1ZStreamReader(ms)
' Read uncompressed data.
Dim reader As StreamReader = New StreamReader(sr)
ExpandString = reader.ReadToEnd()
End Function
To write code in C#
C#

Copy Code

public string ExpandString(byte[] buffer)


{
// Turn buffer into a memory stream.

MemoryStream ms = new MemoryStream(buffer);


// Attach a decompressor stream to the memory stream.
C1ZStr
// Read uncompressed data.
StreamReader reader = new StreamReader(sr);
return reader.ReadToEnd();
}
If you run the project now, you can already experiment with string compression and
decompression. You can change the text in the text box, or paste new content into it, then
compress and expand the string to see how much it compresses.

Step 5: Add code to compress binary data.


Compressing binary data is just as easy as compressing strings. The only difference is that
instead of attaching a StreamWriter object to the compressor stream, you attach a BinaryWriter
object.
Double-click the Compress Data button and add the following code to handle the
btnCompressData_Click event:
To write code in Visual Basic
Visual Basic

Copy Code

Private m_CompressedData As Byte()


Private Sub btnCompressData_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCompressData.Click
' Open the memory stream.
Dim ms As MemoryStream = New MemoryStream()
' Attach a compressor stream to the memory stream.
Dim sw As C1ZStreamWriter = New C1ZStreamWriter(ms)
' Attach a BinaryWriter to the compressor stream.
Dim bw As BinaryWriter = New BinaryWriter(sw)
' Write a bunch of numbers into the stream.
Dim i As Integer
Dim count As Integer = 1000
bw.Write(count)
For i = 0 To count - 1
Dim a As Double = i * Math.PI / 180.0
bw.Write(i)
bw.Write(a)
bw.Write(Math.Sin(a))

bw.Write(Math.Cos(a))
Next i
' Flush any pending output.
bw.Flush()
' Save the compressed data.
m_CompressedData = ms.ToArray()
' Done.
Dim msg As String
msg =String.Format("Generated table with {0} points," & " saved into {1}
bytes", count, m_CompressedData.Length)
Label1.Text = msg
' We can now expand it.
btnExpandData.Enabled = True
End Sub
To write code in C#
C#

Copy Code

private void btnCompressData_Click(object sender, EventArgs e)


{
// Open the memory stream.
MemoryStream ms = new MemoryStream();
// Attach a compressor stream to the memory stream.
C1ZStreamWriter sw = new C1ZStreamWriter(ms);
// Attach a BinaryWriter to the compressor stream.
BinaryWriter bw = new BinaryWriter(sw);
// Write a bunch of numbers into the stream.
int i;
int count = 1000;
bw.Write(count);
for (i = 0 ; i <= count - 1; i++)
{
double a = i * Math.PI / 180.0;
bw.Write(i);
bw.Write(a);
bw.Write(Math.Sin(a));
bw.Write(Math.Cos(a));
}
// Flush any pending output.

bw.Flush();
// Save the compressed data.
m_CompressedData = ms.ToArray();
// Done.
string

msg;

msg =string .Format("Generated table with {0} points," +


" saved into {1} bytes", count, m_CompressedData.Length);
label1.Text = msg;
// We can now expand it.
btnExpandData.Enabled = true;
}
The code starts by declaring a member variable called m_CompressedData which will be used
to hold the compressed data (encoded as a byte array).
Then it sets up the MemoryStream, C1ZStreamWriter, and BinaryWriter objects as before (the
only difference is we're now using a BinaryWriter instead of a StreamWriter).
Next, the code writes data into the stream using the Write method. The BinaryWriter object
overloads this method so you can write all basic object types into streams. Finally, the Flush
method is used as before, to make sure any cached data is written out to the compressed
stream.
Step 6: Add code to expand the binary data.
Expanding the compressed binary data is just a matter of setting up the decompressor stream
and reading the data like you would read it from a regular stream.
Add the following Click event handler code for the Decompress Data command button:
To write code in Visual Basic
Visual Basic

Copy Code

Private Sub btnExpandData_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnExpandData.Click
' Open the memory stream on saved data.
Dim ms As MemoryStream = New MemoryStream(m_CompressedData)
' Attach a decompressor stream to the memory stream.
Dim sr As C1ZStreamReader = New C1ZStreamReader(ms)
' Read the uncompressed data.
Dim i As Integer
Dim br As BinaryReader = New BinaryReader(sr)
Dim count As Integer = br.ReadInt32()
For i = 0 To count - 1

Dim deg As Integer = br.ReadInt32()


Dim rad As Double = br.ReadDouble()
Dim sin As Double = br.ReadDouble()
Dim cos As Double = br.ReadDouble()
Next i
' Done, tell the user about it.
Dim msg As String
msg = String.Format("Read table with {0} points " & "from stream with {1}
bytes.", count, m_CompressedData.Length)
Label1.Text = msg
End Sub
To write code in C#
C#

Copy Code

private void btnExpandData_Click(object sender, EventArgs e)


{
// Open the memory stream on saved data.
MemoryStream ms = new MemoryStream(m_CompressedData);
// Attach a decompressor stream to the memory stream.
C1ZStreamReader sr = new C1ZStreamReader(ms);
// Read the uncompressed data.
int i;
BinaryReader br = new BinaryReader(sr);
int count = br.ReadInt32();
for (i = 0 ; i <= count - 1; i++)
{
int deg = br.ReadInt32();
double rad = br.ReadDouble();
double sin = br.ReadDouble();
double cos = br.ReadDouble();
}
// Done, tell the user about it.
string

msg;

msg = string .Format("Read table with {0} points " +


"from stream with {1} bytes.", count, m_CompressedData.Length);
label1.Text = msg;
}
The code reads the data but does not display it. You can step through it in debug mode to
make sure the data being read is the same that was written in.

If you run the project and click the compress/decompress data buttons, you will see that the
data is saved in an array with 14,125 bytes. To save this data in a regular stream, it would take [4
+ 1000 * (4 + 8 * 3)] = 28,004 bytes. So we compressed it to about half the original size.
This concludes the Compressing Data in Memory tutorial.

Compressing Files
This tutorial shows how you can compress and expand individual files. Note that these are not
zip files; they are just compressed streams on disk. Zip files are covered in the Handling Zip Files
tutorial. Here is what the final application will look like:

Step 1: Create the main form.


Start a new Visual Studio project and from the Toolbox, add the following controls to the form:

Two Button controls along the left edge of the form, as shown in the picture above. In
the Properties window make the following changes:
Button

Button.Text Property

Button.Name Property

Button.Enabled Property

Compress Files

btnCompress

True (Default)

Expand Files

btnExpand

False

Note that the Expand Files button cannot be used until we have some compressed files
to expand.
A Label control on the right of the buttons. This control will display statistics about the
compression/expanding process.

Step 2: Add a reference to the C1Zip assembly.


Go to the Solution Explorer window and click the Show All Files button. Right-click on
References, and select the Add Reference menu option. Select the C1.C1Zip assembly from
the list, or browse to find the C1.C1Zip.2.dll file.
Select the Form1.vb tab (Form1.cs in C#) or go to View|Code to open the Code Editor. At the
top of the file, add the following statements:

To write code in Visual Basic


Visual Basic

Copy Code

Imports System.IO
Imports C1.C1Zip
To write code in C#
C#

Copy Code

using System.IO;
using C1.C1Zip;
This makes the objects defined in the C1Zip and System.IO assemblies visible to the project
and saves a lot of typing.

Step 3: Define the directory names for the compressed and expanded
files.
In the Code Editor of the form, define the following constants:
To write code in Visual Basic
Visual Basic

Copy Code

Private Const DIR_COMP = "\compressed"


Private Const DIR_EXP = "\expanded"
To write code in C#
C#

Copy Code

private const string DIR_COMP = @"\compressed";


private const string DIR_EXP = @"\expanded";
These are the directory names where the compressed and expanded files will be stored (relative
to the directory where the tutorial application is located on your disk).

Step 4: Add code to compress files.


Add the following code to handle the Click event for the Compress Files command button:

To write code in Visual Basic


Visual Basic

Copy Code

Private Sub btnCompress_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnCompress.Click
' Get the application directory.
Dim appPath As String = Application.ExecutablePath
Dim i As Integer = appPath.IndexOf("\bin\")
If i > 0 Then appPath = appPath.Substring(0, i)
' Create a directory for compressed files.
If (Directory.Exists(appPath + DIR_COMP)) Then
Directory.Delete(appPath + DIR_COMP, True)
End If
Directory.CreateDirectory(appPath + DIR_COMP)
' Prepare to collect compression statistics.
Dim count As Long
Dim size As Long
Dim sizeCompressed As Long
Dim ticks As Long = DateTime.Now.Ticks
' Compress all files in the application dir into the compressed dir.
Dim files As String() = Directory.GetFiles(appPath)
Dim srcFile As String
For Each srcFile In files
Dim dstFile As String
dstFile = appPath + DIR_COMP + "\" + Path.GetFileName(srcFile) +
".cmp"
' Compress file.
CompressFile(dstFile, srcFile)
' Update stats.
count = count + 1
size = size + New FileInfo(srcFile).Length
sizeCompressed = sizeCompressed + New FileInfo(dstFile).Length
Next srcFile
' Show stats.
Dim msg As String = String.Format("Compressed {0} files in {1} ms." &
vbCrLf & "Original size:

{2:#,###}" & vbCrLf & "Compressed size: {3:#,###}

({4:0.00}% of original)", count, (DateTime.Now.Ticks - ticks) /


TimeSpan.TicksPerMillisecond, size, sizeCompressed, (sizeCompressed / size) *
100.0)
Label1.Text = msg

' Now we can expand.


btnExpand.Enabled = True
End Sub
To write code in C#
C#

Copy Code

private void btnCompress_Click(object sender, EventArgs e)


{
// Get the application directory.
string appPath = Application.ExecutablePath;
int i = appPath.IndexOf(@"\bin\");
if (i > 0) appPath = appPath.Substring(0, i);
// Create a directory for compressed files.
if ((Directory.Exists(appPath + DIR_COMP)))
Directory.Delete(appPath + DIR_COMP, true);
Directory.CreateDirectory(appPath + DIR_COMP);
// Prepare to collect compression statistics.
long count = 0;
long size = 0;
long sizeCompressed = 0;
long ticks = DateTime.Now.Ticks;
// Compress all files in the application dir into the compressed dir.
foreach (string srcFile in Directory.GetFiles(appPath))
{
string dstFile = appPath + DIR_COMP + @"\" +
Path.GetFileName(srcFile) + ".cmp";
// Compress file.
CompressFile(dstFile, srcFile);
// Update stats.
count++;
size += new FileInfo(srcFile).Length;
sizeCompressed += new FileInfo(dstFile).Length;
}
// Show stats.
string

msg = string .Format("Compressed {0} files in {1} ms.\n\r" +

"Original size:

{2:#,###}\n\r" + "Compressed size: {3:#,###} ({4:0.00}% of

original)", count, (DateTime.Now.Ticks - ticks) /


TimeSpan.TicksPerMillisecond, size, sizeCompressed, (sizeCompressed / size) *
100.0);

label1.Text = msg;
// Now we can expand.
btnExpand.Enabled = true;
}
The main line calls the utility function CompressFile utility method to compress each selected
file. The compressed files are stored in the \compressed directory under the application folder.
They have the same name as the original file, plus a CMP extension.
Add the following code for the CompressFile function:
To write code in Visual Basic
Visual Basic

Copy Code

Private Function CompressFile( dstFile As String, srcFile As String) As


Boolean
' Prepare to compress file.
Dim retval As Boolean = True
Dim srcStream As FileStream = Nothing
Dim dstStream As FileStream = Nothing
Try
' Open the files.
srcStream = New FileStream(srcFile, FileMode.Open, FileAccess.Read)
dstStream = New FileStream(dstFile, FileMode.Create,
FileAccess.Write)
' Open a compressor stream on the destination file.
Dim sw As C1ZStreamWriter = New C1ZStreamWriter(dstStream)
' Copy the source into the compressor stream.
StreamCopy(sw, srcStream)
Catch
' Exception? Tell the caller we failed.
retval = False
Finally
' Always close our streams.
If Not (srcStream Is Nothing) Then srcStream.Close()
If Not (dstStream Is Nothing) Then dstStream.Close()
End Try
' Done.
CompressFile = False
End Function
To write code in C#

C#

Copy Code

private bool CompressFile(string

dstFile, string

srcFile)

{
// Prepare to compress file.
bool retval = true;
FileStream srcStream = null;
FileStream dstStream = null;
try
{
// Open the files.
srcStream = new FileStream(srcFile, FileMode.Open, FileAccess.Read);
dstStream = new FileStream(dstFile, FileMode.Create,
FileAccess.Write);
// Open a compressor stream on the destination file.
C1ZStreamWriter sw = new C1ZStreamWriter(dstStream);
// Copy the source into the compressor stream.
StreamCopy(sw, srcStream);
}
catch
{
// Exception? Tell the caller we failed.
retval = false;
}
finally
{
// Always close our streams.
if (srcStream != null) srcStream.Close();
if (dstStream != null) dstStream.Close();
}
// Done.
return false;
}
The function starts by creating two new file streams: one for the source file and one for the
compressed file. Then it creates a C1ZStreamWriter object and attaches it to the destination
stream. Next, it calls the StreamCopy function to transfer data from the source file and write it
into the compressor stream.
Finally, the function closes both streams. Note the use of the Finally statement to ensure that
both streams are properly closed even if there are exceptions while the function is executing.
The StreamCopy function simply copies bytes from one stream to another. Here's the code:

To write code in Visual Basic


Visual Basic

Copy Code

Private Sub StreamCopy(dstStream As Stream, srcStream As Stream)


Dim buffer(32768) As Byte
Dim read As Integer
Do
read = srcStream.Read(buffer, 0, buffer.Length)
dstStream.Write(buffer, 0, read)
Loop While read > 0
dstStream.Flush()
End Sub
To write code in C#
C#

Copy Code

private void StreamCopy(Stream dstStream, Stream srcStream)


{
byte[] buffer= new byte[32768];
for (;;)
{
int read = srcStream.Read(buffer, 0, buffer.Length);
if (read == 0) break;
dstStream.Write(buffer, 0, read);
}
dstStream.Flush();
}
Note that the function calls the Flush method after it is done to ensure that any cached data is
written out when the function is done copying. This is especially important when dealing with
compressed streams, since they cache substantial amounts of data in order to achieve good
compression rates.

Step 5: Add code to expand files.


Add the following code to handle the Click event for the Expand Files command button:
To write code in Visual Basic
Visual Basic

Copy Code

Private Sub btnExpand_Click(sender As Object, e As EventArgs) Handles


btnExpand.Click
' Get the application directory.
Dim appPath As String = Application.ExecutablePath
Dim i As Integer

= appPath.IndexOf("\bin\")

If i > 0 Then appPath = appPath.Substring(0, i)


' Create a directory for expanded files.
If Directory.Exists(appPath + DIR_EXP) Then
Directory.Delete(appPath + DIR_EXP, True)
End If
Directory.CreateDirectory(appPath + DIR_EXP)
' Prepare to collect compression statistics.
Dim count As Long
Dim size As Long
Dim sizeExpanded As Long
Dim ticks As Long = DateTime.Now.Ticks
' Expand all files in the "compressed" dir to the "expanded" dir.
Dim srcFile As String
Dim files As String()
files = Directory.GetFiles(appPath + DIR_COMP)
For Each srcFile In files
' Expand file.
Dim dstFile As String = appPath + DIR_EXP + "\" +
Path.GetFileName(srcFile)
dstFile = dstFile.Replace(".cmp", "")
ExpandFile(dstFile, srcFile)
' Update stats.
count = count + 1
size = size + New FileInfo(srcFile).Length
sizeExpanded = sizeExpanded + New FileInfo(dstFile).Length
Next srcFile
' Show stats.
Dim msg As String
msg = String.Format("Expanded {0} files in {1} ms." & vbCrLf & "Original
size:

{2:#,###}" & vbCrLf & "Expanded size: {3:#,###} ({4:0.00} x size of

compressed)", count, (DateTime.Now.Ticks - ticks) /


TimeSpan.TicksPerMillisecond, size, sizeExpanded, sizeExpanded / size)
Label1.Text = msg
End Sub
To write code in C#

C#

Copy Code

private void btnExpand_Click(object sender, EventArgs e)


{
// Get the application directory.
string appPath = Application.ExecutablePath;
int i = appPath.IndexOf(@"\bin\");
if (i > 0) appPath = appPath.Substring(0, i);
// Create a directory for expanded files.
if (Directory.Exists(appPath + DIR_EXP))
Directory.Delete(appPath + DIR_EXP, true);
Directory.CreateDirectory(appPath + DIR_EXP);
// Prepare to collect compression statistics.
long count = 0;
long size = 0;
long sizeExpanded = 0;
long ticks = DateTime.Now.Ticks;
// Expand all files in the "compressed" dir to the "expanded" dir.
foreach (string srcFile in Directory.GetFiles(appPath + DIR_COMP))
{
// Expand file.
string

dstFile = appPath + DIR_EXP + @"\" +

Path.GetFileName(srcFile);
dstFile = dstFile.Replace(".cmp", "");
ExpandFile(dstFile, srcFile);
// Update stats.
count++;
size += new FileInfo(srcFile).Length;
sizeExpanded += new FileInfo(dstFile).Length;
}
// Show stats.
string msg = string .Format("Expanded {0} files in {1} ms.\r\n" +
"Original size:

{2:#,###}\r\n" + "Expanded size: {3:#,###} ({4:0.00} x size

of compressed)", count, (DateTime.Now.Ticks - ticks) /


TimeSpan.TicksPerMillisecond, size, sizeExpanded, sizeExpanded / size);
label1.Text = msg;
}
The main line calls the utility function ExpandFile utility method to expand the files that were
compressed earlier. The expanded files are stored in the \expanded directory under the
application folder. They have the same name as the original file, minus the CMP extension.
Here's the code for the ExpandFile function:

To write code in Visual Basic


Visual Basic

Copy Code

Private Function ExpandFile(dstFile As String, srcFile As String) As Boolean


' Prepare to expand file.
Dim retval As Boolean = True
Dim srcStream As FileStream = Nothing
Dim dstStream As FileStream = Nothing
Try
' Open the files.
srcStream = New FileStream(srcFile, FileMode.Open, FileAccess.Read)
dstStream = New FileStream(dstFile, FileMode.Create,
FileAccess.Write)
' Open an expander stream on the compressed source.
Dim sr As C1ZstreamReader = New C1ZStreamReader(srcStream)
' Copy the expander stream into the destination file.
StreamCopy(dstStream, sr)
Catch
' Exception? Tell the caller we failed.
retval = False
Finally
' Always close our streams.
If Not (srcStream Is Nothing) Then srcStream.Close()
If Not (dstStream Is Nothing) Then dstStream.Close()
End Try
' Done.
ExpandFile = retval
End Sub
To write code in C#
C#

Copy Code

private bool ExpandFile(string dstFile, string srcFile)


{
// Prepare to expand file.
bool retval = true;
FileStream srcStream = null;
FileStream dstStream = null;

try
{
// Open the files.
srcStream = new FileStream(srcFile, FileMode.Open, FileAccess.Read);
dstStream = new FileStream(dstFile, FileMode.Create,
FileAccess.Write);
// Open an expander stream on the compressed source.
C1ZStreamReader sr = new C1ZStreamReader(srcStream);
// Copy the expander stream into the destination file.
StreamCopy(dstStream, sr);
}
catch
{
// Exception? Tell the caller we failed.
retval = false;
}
finally
{
// Always close our streams.
if (srcStream != null) srcStream.Close();
if (dstStream != null) dstStream.Close();
}
// Done.
return retval;
}
The function is similar to CompressFile, except it attaches a C1ZStreamReader to the source
stream instead of attaching a C1ZStreamWriter to the destination stream.
This concludes the Compressing Files tutorial.

Compressed Serialization
This tutorial shows how you can serialize objects in compressed files, and then load them back
into the memory.
The sample creates a data table using the NorthWind database. The table is saved (serialized)
into regular and compressed streams. Finally, the data is loaded back from either stream. Here
is what the final application will look like:

Step 1: Create the main form.


Start a new Visual Studio project and from the Toolbox, add the following controls to the form:

Four Button controls along the left edge of the form, as shown in the picture above. In
the Properties window make the following changes to each Button control:
Button Button.Text Property

Button.Name Property

Button.Enabled Property

Create Data Table

btnCreate

True (Default)

Save Data Table

btnSave

False

Load Data Table

btnLoad

False

Load Compressed Data Table

btnLoadCompressed

False

Note that the save and load buttons cannot be used until the data table has been
created or saved.
A DataGridView control on the right of the form.
A ToolStripStatusLabel control docked at the bottom of the form. To add this control,
first add a StatusStrip control to the form. Then click the Add ToolStripStatusLabel
drop-down arrow and select StatusLabel. A ToolStripStatusLabel control appears and
is docked at the bottom of the form.

Step 2: Add references and Imports statements.

Go to the Solution Explorer window and click the Show All Files button. Right-click on
References, and select the Add Reference menu option. Select the C1.C1Zip assembly from the
list, or browse to find the C1.C1Zip.2.dll file.
Select the Form1.vb tab (Form1.cs in C#) or go to View|Code to open the Code Editor. At the
top of the file, add the following statements:
To write code in Visual Basic
Visual Basic

Copy Code

Imports System.IO
Imports System.Data.OleDb
Imports System.Runtime.Serialization.Formatters.Binary
Imports C1.C1Zip
To write code in C#
C#

Copy Code

using System.IO;
using System.Data.OleDb;
using System.Runtime.Serialization.Formatters.Binary;
using C1.C1Zip;
This declares the namespaces of the classes used in the project.

Step 3: Declare constants.


In the Code Editor of the form, type or copy the following lines in the body of the form
implementation:
To write code in Visual Basic
Visual Basic

Copy Code

Private Const FN_REGULAR = "\DataTable.regular"


Private Const FN_COMPRESSED = "\DataTable.compressed"
Private Const MDBFILE = " C:\Users\\Documents\ComponentOne
Samples\common\C1NWIND.MDB"
To write code in C#

C#

Copy Code

private const string FN_REGULAR = @"\DataTable.regular";


private const string FN_COMPRESSED = @"\DataTable.compressed";
private const string MDBFILE = @"C C:\Users\\Documents\ComponentOne
Samples\common\C1NWIND.MDB";
These constants define the name of the database used to populate the data table and the file
names used to serialize the data.

Step 4: Add code to create the data table.


Add the following code to handle the Click event for the Create Data Table button:
To write code in Visual Basic
Visual Basic

Copy Code

Private Sub btnCreate_Click(sender As Object,e As EventArgs) Handles


btnCreate.Click
' Open the table.
Dim conn As String
conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MDBFILE & ";"
Dim rs As String = "select * from customers"
' Show status.
Cursor = Cursors.WaitCursor
ToolStripStatusLabel1.Text = "Loading data from mdb file..."
' Load data.
Dim da As OleDbDataAdapter = New OleDbDataAdapter(rs, conn)
Dim ds As DataSet = New DataSet()
Try
da.Fill(ds)
Catch
MessageBox.Show("Could not load data from " + MDBFILE)
End Try
' Show status.
Cursor = Cursors.Default
ToolStripStatusLabel1.Text = "Loaded " & ds.Tables(0).Rows.Count & "
records from mdb file."
' Bind to the grid.
DataGridView1.DataSource = ds.Tables(0)

' Enable the save button.


btnSave.Enabled = True
End Sub
To write code in C#
C#

Copy Code

private void btnCreate_Click(object sender,EventArgs e)


{
// Open the table.
string conn =

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + MDBFILE

+ ";";
string rs = "select * from customers";
// Show status.
Cursor = Cursors.WaitCursor;
toolStripStatusLabel1.Text = "Loading data from mdb file...";
// Load data.
OleDbDataAdapter da = new OleDbDataAdapter(rs, conn);
DataSet ds = new DataSet();
try
{
da.Fill(ds);
}
catch
{
MessageBox.Show("Could not load data from " + MDBFILE);
}
// Show status.
Cursor = Cursors.Default;
toolStripStatusLabel1.Text = "Loaded " + ds.Tables[0].Rows.Count +

"

records from mdb file.";


// Bind to the grid.
dataGridView1.DataSource = ds.Tables[0];
// Enable the save button.
btnSave.Enabled = true;
}
The function uses standard ADO.NET objects and methods to create and populate a DataTable
object, which is then bound to the DataGrid control.

Step 5: Add code to save the data table.

Add the following code to handle the Click event for the Save Data Table button:
To write code in Visual Basic
Visual Basic

Copy Code

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles


btnSave.Click
' Get the data table from the grid.
Dim dt As DataTable = DataGridView1.DataSource
' Show status.
Cursor = Cursors.WaitCursor
ToolStripStatusLabel1.Text = "Serializing data to regular file..."
' Serialize the data set to a regular file.
Dim fn As String = Application.StartupPath + FN_REGULAR
Dim fs As FileStream = New FileStream(fn, FileMode.Create)
Dim bf As BinaryFormatter = New BinaryFormatter()
bf.Serialize(fs, dt)
Dim lenRegular As Long = fs.Length
fs.Close()
' Show status.
Cursor = Cursors.WaitCursor
ToolStripStatusLabel1.Text = "Serializing data to compressed file..."
' Serialize the data set to a compressed file.
fn = Application.StartupPath & FN_COMPRESSED
fs = New FileStream(fn, FileMode.Create)
Dim compressor As C1ZStreamWriter = New C1ZStreamWriter(fs)
bf = New BinaryFormatter()
bf.Serialize(compressor, dt)
Dim lenCompressed As Long = fs.Length
fs.Close()
' Show status.
Cursor = Cursors.Default
ToolStripStatusLabel1.Text = string.Format( "Saved to regular file
({0:#,###} bytes) and " & "compressed file ({1:#,###} bytes)", lenRegular,
lenCompressed)
' Enable the load buttons.
btnLoad.Enabled = True
btnLoadCompressed.Enabled = True
End Sub
To write code in C#

C#

Copy Code

private void btnSave_Click(object sender, EventArgs e)


{
// Get the data table from the grid.
DataTable dt = (DataTable)dataGridView1.DataSource;
// Show status.
Cursor = Cursors.WaitCursor;
toolStripStatusLabel1.Text = "Serializing data to regular file...";
// Serialize the data set to a regular file.
string fn = Application.StartupPath + FN_REGULAR;
FileStream fs = new FileStream(fn, FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, dt);
long lenRegular = fs.Length;
fs.Close();
// Show status.
Cursor = Cursors.WaitCursor;
toolStripStatusLabel1.Text = "Serializing data to compressed file...";
// Serialize the data set to a compressed file.
fn = Application.StartupPath + FN_COMPRESSED;
fs = new FileStream(fn, FileMode.Create);
C1ZStreamWriter compressor = new C1ZStreamWriter(fs);
bf = new BinaryFormatter();
bf.Serialize(compressor, dt);
long lenCompressed = fs.Length;
fs.Close();
// Show status.
Cursor = Cursors.Default;
toolStripStatusLabel1.Text = string.Format("Saved to regular file
({0:#,###} bytes) and " + "compressed file ({1:#,###} bytes)", lenRegular,
lenCompressed);
// Enable the load buttons.
btnLoad.Enabled = true;
btnLoadCompressed.Enabled = true;
}
The first set of code serializes the DataTable into a regular file, and the second serializes the
DataTable into a compressed file. Note that only one additional line is required to compress
the data.

In both cases, the serialization is executed by the BinaryFormatter object. The only difference is
that in the first case, the Serialize method is called with a regular file stream as a parameter; in
the second, a C1ZStreamWriter is used instead.

Step 6: Add code to load the data table from the regular file.
Add the following code to handle the Click event for the Load Data Table button:
To write code in Visual Basic
Visual Basic

Copy Code

Private Sub btnLoad_Click(sender As Object, e As EventArgs) Handles


btnLoad.Click
' Clear grid, show status.
Cursor = Cursors.WaitCursor
DataGridView1.DataSource = Nothing
ToolStripStatusLabel1.Text = "Loading from regular file..."
' Deserialize from regular file.
Dim fn As String = Application.StartupPath & FN_REGULAR
Dim fs As FileStream = New FileStream(fn, FileMode.Open)
Dim ticks As Long = DateTime.Now.Ticks
Dim bf As BinaryFormatter = New BinaryFormatter()
Dim dt As DataTable = bf.Deserialize(fs)
Dim ms As Long = (DateTime.Now.Ticks - ticks) /
TimeSpan.TicksPerMillisecond
fs.Close()
' Show result.
Cursor = Cursors.Default
DataGridView1.DataSource = dt
ToolStripStatusLabel1.Text = "Loaded from regular file in " &
ms.ToString() & " ms."
End Sub
To write code in C#
C#

Copy Code

private void btnLoad_Click(object sender, EventArgs e)


{
// Clear grid, show status.

Cursor = Cursors.WaitCursor;
dataGridView1.DataSource = null;
toolStripStatusLabel1.Text = "Loading from regular file...";
// Deserialize from regular file.
string fn = Application.StartupPath + FN_REGULAR;
FileStream fs = new FileStream(fn, FileMode.Open);
long ticks = DateTime.Now.Ticks;
BinaryFormatter bf = new BinaryFormatter();
DataTable dt = (DataTable)bf.Deserialize(fs);
long ms = (DateTime.Now.Ticks - ticks) / TimeSpan.TicksPerMillisecond;
fs.Close();
// Show result.
Cursor = Cursors.Default;
dataGridView1.DataSource = dt;
toolStripStatusLabel1.Text = "Loaded from regular file in " +
ms.ToString() + " ms.";
}
The first main line of code creates a new BinaryFormatter object and the second one calls its
Deserialize method. The Deserialize method takes a single parameter: the stream in which the
object is defined. In this case, the stream is a regular file stream.

Step 7: Add code to load the data table from the compressed file.
Add the following code to handle the Click event for the Load Compressed Data Table button:
To write code in Visual Basic
Visual Basic

Copy Code

Private Sub btnLoadCompressed_Click(sender As Object, e As EventArgs) Handles


btnLoadCompressed.Click
' Clear grid, show status.
Cursor = Cursors.WaitCursor
DataGridView1.DataSource = Nothing
ToolStripStatusLabel1.Text = "Loading from compressed file..."
' Deserialize from compressed file.
Dim fn As String = Application.StartupPath + FN_COMPRESSED
Dim fs As FileStream = New FileStream(fn, FileMode.Open)
Dim ticks As Long

= DateTime.Now.Ticks

Dim decompressor As C1ZstreamReader


decompressor = New C1ZStreamReader(fs)
Dim bf As BinaryFormatter = New BinaryFormatter()

Dim dt As DataTable = bf.Deserialize(decompressor)


Dim ms As Long = (DateTime.Now.Ticks - ticks) /
TimeSpan.TicksPerMillisecond
fs.Close()
' Show result.
Cursor = Cursors.Default
DataGridView1.DataSource = dt
ToolStripStatusLabel1.Text = "Loaded from compressed file in " &
ms.ToString() & " ms."
End Sub
To write code in C#
C#

Copy Code

private void btnLoadCompressed_Click(object sender, EventArgs e)


{
// Clear grid, show status.
Cursor = Cursors.WaitCursor;
dataGridView1.DataSource = null;
toolStripStatusLabel1.Text = "Loading from compressed file...";
// Deserialize from compressed file.
string fn = Application.StartupPath + FN_COMPRESSED;
FileStream fs = new FileStream(fn, FileMode.Open);
long ticks = DateTime.Now.Ticks;
C1ZStreamReader decompressor;
decompressor = new C1ZStreamReader(fs);
BinaryFormatter bf = new BinaryFormatter();
DataTable dt = (DataTable)bf.Deserialize(decompressor);
long ms = (DateTime.Now.Ticks - ticks) / TimeSpan.TicksPerMillisecond;
fs.Close();
// Show result.
Cursor = Cursors.Default;
dataGridView1.DataSource = dt;
toolStripStatusLabel1.Text = "Loaded from compressed file in " +
ms.ToString() + " ms.";
}
The main lines are similar to the code used to deserialize data from a regular file. The only
difference is that instead of passing a regular file stream to the Deserialize method, we now use
a C1ZStreamReader object.
This concludes the Compressed Serialization tutorial.

Handling Zip Files


This tutorial shows how you can handle zip files, including the following operations:

Creating a zip file.


Opening an existing zip file.
Adding entries to the zip file.
Extracting entries from the zip file.
Removing entries from the zip file.
Expanding entries into memory streams.
Testing the integrity of a zip file.

Here is what the final application will look like:

Note: This is a very simple application, designed to highlight the main functionality of the
C1ZipFile object. The distribution disk also includes a more sophisticated version, which
supports more advanced features such as drag and drop, zipping folders, setting the
compression level, and so on.

Step 1: Create the main form.


Start a new Visual Studio project.
1.

From the Toolbox, add the following controls to the form:


o Seven Button controls along the left edge of the form, as shown in the picture
above. In the Properties window make the following changes to each Button
control:

Button

Button.Text Property

Button.Name Property

Create Zip File

btnNew

Open Zip File

btnOpen

Add Files

btnAdd

Extract Files

btnExtract

Remove Files

btnRemove

View File

btnView

Test Zip File

btnTest

A ListView control covering the right part of the form. In the Properties
window, click on the ellipsis button next to the Columns property. The
ColumnHeader Collection Editor dialog box appears.

Note: The Column Header Collection Editor can also be accessed by clicking Edit
Columns in the ListView Tasks menu. To access the ListView Tasks menu, click the smart
tag ( ) in the upper right corner of the ListView control.

2.

Click the Add button to add five ColumnHeaders, and then set the Text property of
each column to File, Date, Size, Compressed, and Amount, respectively.
Here is what the ColumnHeader Collection Editor should look like:

3.

Select OK to close the editor box.


Note that to view the column headers, in the Properties window set the View property
to Details or in the ListView Tasks menu, select Details from the View drop-down box.

Step 2: Add a reference to the C1Zip assembly.


Go to the Solution Explorer window, right-click on References, and select the Add Reference
menu option. Select the C1.C1Zip assembly from the list, or browse to find the C1.C1Zip.2.dll
file.
Select the Form1.vb tab (Form1.cs in C#) or go to View|Code to open the Code Editor. At the
top of the file, add the following directives:

To write code in Visual Basic


Visual Basic

Copy Code

Imports System.IO
Imports C1.C1Zip
To write code in C#
C#

Copy Code

using System.IO;
using C1.C1Zip;
This makes the objects defined in the C1Zip and System.IO assemblies visible to the project.

Step 3: Declare a C1ZipFile object.


Switch to the Code Editor and type (or copy) the following data member declaration:
To write code in Visual Basic
Visual Basic

Copy Code

Private m_Zip As C1ZipFile


To write code in C#
C#

Copy Code

private m_Zip As C1ZipFile;


This is the main object in this application. It implements the methods used to handle zip files.

Step 4: Add code to initialize the C1ZipFile object.


Add the following code to the Form_Load event:
To write code in Visual Basic
Visual Basic

Copy Code

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


' Create the C1ZipFile member.
m_Zip = New C1ZipFile()
End Sub
To write code in C#
C#

Copy Code

private void Form1_Load(object sender, EventArgs e)


{
// Create the C1ZipFile member.
m_Zip = new C1ZipFile();
}
This code creates a new C1ZipFile object and assigns it to the m_Zip member. Note that the
C1ZipFile object cannot be used yet. It needs to be attached to an existing zip file first using the
Open method (or to a new one using the Create method).

Step 5: Add code to create a zip file.


Add the following code to handle the Click event for the Create Zip File command button:
To write code in Visual Basic
Visual Basic

Copy Code

Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnNew.Click
' Show open file dialog.
Dim fo As SaveFileDialog = New SaveFileDialog()
fo.FileName = "*.zip"
If fo.ShowDialog() <> Windows.Forms.DialogResult.OK Then
Exit Sub
End If
' Open zip file.
Try
m_Zip.Create(fo.FileName)
Catch
MessageBox.Show("Can't create ZIP file, please try again.", "C1Zip")
End Try

' Update display.


UpdateDisplay()
End Sub
To write code in C#
C#

Copy Code

private void btnNew_Click(object sender, EventArgs e)


{
// Show open file dialog.
SaveFileDialog fo = new SaveFileDialog();
fo.FileName = "*.zip";
if (fo.ShowDialog() != DialogResult.OK ) return;
// Open zip file.
try
{
m_Zip.Create(fo.FileName);
}
catch
{
MessageBox.Show("Can't create ZIP file, please try again.", "C1Zip");
}
// Update display.
UpdateDisplay();
}

Step 6: Add code to open a zip file.


Add the following code to handle the Click event for the Open Zip File command button:
To write code in Visual Basic
Visual Basic

Copy Code

Private Sub btnOpen_Click(sender As Object, e As EventArgs) Handles


btnOpen.Click
' Show open file dialog.
Dim fo As OpenFileDialog = New OpenFileDialog()
fo.FileName = "*.zip"
If fo.ShowDialog() <> Windows.Forms.DialogResult.OK Then Exit Sub

Try
m_Zip.Open(fo.FileName)
Catch
MessageBox.Show("Invalid ZIP file, please try again.")
End Try
' Update display.
UpdateDisplay()
End Sub
To write code in C#
C#

Copy Code

private void btnOpen_Click(object sender, EventArgs e)


{
// Show open file dialog.
OpenFileDialog fo = new OpenFileDialog();
fo.FileName = "*.zip";
if (fo.ShowDialog() != DialogResult.OK ) return;
try
{
m_Zip.Open(fo.FileName);
}
catch
{
MessageBox.Show("Invalid ZIP file, please try again.");
}
// Update display.
UpdateDisplay();
}
The main line calls the Open method on the C1ZipFile object to attach the object to an existing
zip file. Note the use of a Try/Catch statement, mainly to handle situations where the use
selects a file that is not a zip file.
After opening the file, the code calls the UpdateDisplay utility function to display the contents
of the zip file.

Step 7: Add code to update the display.


Next, add the UpdateDisplay utility function to display the contents of the zip file:
To write code in Visual Basic

Visual Basic

Copy Code

Private Sub UpdateDisplay()


' Update the ListView control to show the zip file contents.
With ListView1
' Remove any existing items.
.Items.Clear()
' Add each entry.
Dim ze As C1ZipEntry
For Each ze In m_Zip.Entries
' Calculate the compression amount.
Dim pct As Double = 0
If ze.SizeUncompressed > 0 Then
pct = 1 - ze.SizeCompressed / ze.SizeUncompressed
End If
' Build ListView item.
Dim items(4) As String
items(0) = ze.FileName
items(1) = Format(ze.Date, "MM/dd/yy")
items(2) = Format(ze.SizeUncompressed, "#,##0")
items(3) = Format(ze.SizeCompressed, "#,##0")
items(4) = Format(pct, "00 %")
Dim lvi As ListViewItem = New ListViewItem(items)
' Save ZipEntry into item tag.
lvi.Tag = ze
' Add item to ListView.
.Items.Add(lvi)
Next ze
' Update UI.
Dim hasEntries As Boolean = (.Items.Count > 0)
btnExtract.Enabled = hasEntries
btnRemove.Enabled = hasEntries
btnTest.Enabled = hasEntries
End With
End Sub
To write code in C#
C#

Copy Code

private void UpdateDisplay()


{
// Remove any existing items.
listView1.Items.Clear();
// Add each entry.
foreach (C1ZipEntry ze in m_Zip.Entries)
{
// Calculate the compression amount.
double pct = 0;
if (ze.SizeUncompressed > 0)
{
pct = 1 - (((double)ze.SizeCompressed) /
((double)ze.SizeUncompressed));
}
// Build ListView item.
ListViewItem lvi = new ListViewItem(new string[] { ze.FileName,
Microsoft.VisualBasic.Strings.Format(ze.Date, "MM/dd/yy"),
Microsoft.VisualBasic.Strings.Format(ze.SizeUncompressed, "#,##0"),
Microsoft.VisualBasic.Strings.Format(ze.SizeCompressed, "#,##0"),
Microsoft.VisualBasic.Strings.Format(pct, "00 %") });
// Save ZipEntry into item tag.
lvi.Tag = ze;
// Add item to ListView.
listView1.Items.Add(lvi);
}
// Update UI.
bool hasEntries = (listView1.Items.Count > 0);
btnExtract.Enabled = hasEntries;
btnRemove.Enabled = hasEntries;
btnTest.Enabled = hasEntries;
}
The main lines start by declaring a C1ZipEntry object and using it in a ForEach loop over the
entries in the zip file (m_Zip.Entries).
For each entry, the function creates a ListViewItem containing the information extracted from
the C1ZipEntry object and adds the new entry to the ListView control. Note that the C1ZipEntry
object itself is also saved in the Tag property of the ListView items.
Finally, the code enables or disables the command buttons depending on whether or not there
are entries available to be extracted, removed or tested.

Step 8: Add code to test the integrity the zip file.


Add the following code to handle the Click event for the Test Zip File command button:

To write code in Visual Basic


Visual Basic

Copy Code

Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles


btnTest.Click
' Test each entry.
Dim ze As C1ZipEntry
For Each ze In m_Zip.Entries
If Not ze.CheckCRC32() Then
MessageBox.Show("** Entry " & ze.FileName & " has errors.",
"C1Zip", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Next
' If we got here, everything is OK.
MessageBox.Show("All entries passed CRC check", "C1Zip")
End Sub
To write code in C#
C#

Copy Code

private void btnTest_Click(object sender, EventArgs e)


{
// Test each entry.
foreach (C1ZipEntry ze in m_Zip.Entries)
{
if (!ze.CheckCRC32())
{
MessageBox.Show("** Entry " + ze.FileName + " has errors.",
"C1Zip", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
// If we got here, everything is OK.
MessageBox.Show("All entries passed CRC check", "C1Zip");
}
The main lines declare a C1ZipEntry variable and use it to loop over the entries in the zip file.
The routine then calls the CheckCRC32 method on each entry to check whether the actual
checksum of the bytes stored in the file matches the checksum stored in the entry header. The

function returns true if the values match and false if they don't (which indicates the entry is
corrupted).

Step 9: Add code to view the contents of an entry.


Add the following code to handle the Click event for the View File command button:
To write code in Visual Basic
Visual Basic

Copy Code

Private Sub btnView_Click(sender As Object, e As EventArgs) Handles


btnView.Click
' Get the first selected item that is not a directory.
Dim ze As C1ZipEntry = Nothing
Dim lvi As ListViewItem
For Each lvi In ListView1.SelectedItems
Dim zeItem As C1ZipEntry = lvi.Tag
If (zeItem.Attributes And FileAttributes.Directory) = 0 Then
ze = zeItem
Exit For
End If
Next lvi
' Make sure we got something.
If ze Is Nothing Then
MessageBox.Show("Sorry, no files to show...", "C1Zip")
Exit Sub
End If
' Read entry content into a string.
Dim entry As Stream = ze.OpenReader()
Dim sr As StreamReader = New StreamReader(entry)
Dim entryText As String = sr.ReadToEnd()
entry.Close()
' Make sure the entry is not too big for the MessageBox.
If entryText.Length > 16000 Then
entryText = entryText.Substring(0, 16000)
End If
' Show the entry in the message box.
MessageBox.Show(entryText, ze.FileName)
End Sub
To write code in C#

C#

Copy Code

private void btnView_Click(object sender, EventArgs e)


{
// Get the first selected item that is not a directory.
C1ZipEntry ze = null;
foreach (ListViewItem lvi in listView1.SelectedItems)
{
C1ZipEntry zeItem = lvi.Tag as C1ZipEntry;
if ((zeItem.Attributes == 0) && (FileAttributes.Directory == 0))
{
ze = zeItem;
break;
}
}
// Make sure we got something.
if (ze == null )
{
MessageBox.Show("Sorry, no files to show...", "C1Zip");
return;
}
// Read entry content into a string.
Stream entry = ze.OpenReader();
StreamReader sr = new StreamReader(entry);
string

entryText = sr.ReadToEnd();

entry.Close();
// Make sure the entry is not too big for the MessageBox.
if (entryText.Length > 16000 )
{
entryText = entryText.Substring(0, 16000);
}
// Show the entry in the message box.
MessageBox.Show(entryText, ze.FileName);
}
The function starts by choosing the first selected zip entry that is not a subdirectory. If a valid
entry cannot be found, the function exits.
The function then calls the OpenReader method to obtain a Stream that can be used to read
the contents of the entry. There are no temporary files or additional delays involved in this step;
the data is expanded as it is read from the stream.

Next, the function reads the entry content directly into a string using the ReadToEnd method
on the StreamReader object, then closes the stream.
Finally, the string is truncated and displayed in a message box.
Note that this function was designed to show the contents of short text files. If you try to view
the contents of binary files, it will show only a couple of characters.

Step 10: Add code to add entries to the zip file.


Add the following code to handle the Click event for the Add Files command button:
To write code in Visual Basic
Visual Basic

Copy Code

Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles


btnAdd.Click
' Get list of files to add.
Dim fo As OpenFileDialog = New OpenFileDialog()
fo.Multiselect = True
fo.FileName = "*.*"
If fo.ShowDialog <> Windows.Forms.DialogResult.OK Then Exit Sub
' Add files in the list.
Dim file As String
For Each file In fo.FileNames()
m_Zip.Entries.Add(file)
Next file
' Done.
UpdateDisplay()
End Sub
To write code in C#
C#

Copy Code

private void btnAdd_Click(object sender, EventArgs e)


{
// Get list of files to add.
OpenFileDialog fo = new OpenFileDialog();
fo.Multiselect = true;
fo.FileName = "*.*";

if (fo.ShowDialog() == DialogResult.OK)
{
// Add files in the list.
foreach (string file in fo.FileNames)
{
m_Zip.Entries.Add(file);
}
// Done.
UpdateDisplay();
}
}
Adding new entries to a zip file is easy. The main line simply calls the Add method on the
C1ZipFile object, passing a string that contains the full name of the file to be added. Thats all
there is to it.

Step 11: Add code to extract a zip entry.


Add the following code to handle the Click event for the Extract Files command button:
To write code in Visual Basic
Visual Basic

Copy Code

Private Sub btnExtract_Click(sender As Object, e As EventArgs) Handles


btnExtract.Click
' Make sure we have some selected entries.
Dim cnt As Integer = ListView1.SelectedIndices.Count
If cnt = 0 Then
MessageBox.Show("Sorry, no files to extract...", "C1Zip")
Exit Sub
End If
' Confirm with user.
Dim dr As DialogResult
Dim msg As String
msg = "Please confirm that you want to extract " + cnt.ToString() + "
entries."
dr = MessageBox.Show(msg, "C1Zip", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question)
If dr <> Windows.Forms.DialogResult.OK Then Exit Sub
' Extract all selected entries
Dim lvi As ListViewItem
Dim ze As C1ZipEntry

For Each lvi In ListView1.SelectedItems


ze = lvi.Tag
If ze.SizeCompressed > 0 Then
m_Zip.Entries.Extract(ze.FileName)
End If
Next lvi
' Done.
UpdateDisplay()
End Sub
To write code in C#
C#

Copy Code

private void btnExtract_Click(object sender, EventArgs e)


{
// Make sure we have some selected entries.
int cnt = listView1.SelectedIndices.Count;
if (cnt == 0)
{
MessageBox.Show("Sorry, no files to extract...", "C1Zip");
return;
}
// Confirm with user.
DialogResult dr;
string

msg;

msg = "Please confirm that you want to extract " + cnt.ToString() + "
entries.";
dr = MessageBox.Show(msg, "C1Zip", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question);
if ( dr != DialogResult.OK )

return;

// Extract all selected entries.


C1ZipEntry ze;
foreach (ListViewItem lvi in ListView1.SelectedItems)
{
ze = (C1ZipEntry)lvi.Tag;
if ( ze.SizeCompressed > 0 )
{
m_Zip.Entries.Extract(ze.FileName);
}
}

// Done.
UpdateDisplay();
}
The most important line calls the Extract method on the Entries property of the C1ZipFile object.
The parameter is the string that contains the file name of the entry (which is stored in the
entry's FileName property).
By default, the Extract method expands the entry and saves it in the same directory where the
zip file is located. There are other versions of this method that allow you to specify the
destination directory and file name for the expanded file. For more details, see the C1.C1Zip
Namespace section.

Step 12: Add code to remove entries from the zip file.
Add the following code to handle the Click event for the Remove Files command button:
To write code in Visual Basic
Visual Basic

Copy Code

Private Sub btnRemove_Click(sender As Object, e As EventArgs) Handles


btnRemove.Click
' Make sure we have some selected entries.
Dim cnt As Integer = ListView1.SelectedIndices.Count
If cnt = 0 Then
MessageBox.Show("Oops, no files to remove...", "C1Zip")
Exit Sub
End If
' Confirm with user.
Dim dr As DialogResult
Dim msg As String
msg = "Please confirm that you want to delete " + cnt.ToString() + "
entries."
dr = MessageBox.Show(msg, "C1Zip", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question)
If dr <> Windows.Forms.DialogResult.OK Then Exit Sub
' Delete all selected entries.
Dim lvi As ListViewItem
Dim ze As C1ZipEntry
For Each lvi In ListView1.SelectedItems
ze = lvi.Tag
m_Zip.Entries.Remove(ze.FileName)

Next lvi
' Done.
UpdateDisplay()
End Sub
To write code in C#
C#

Copy Code

private void btnRemove_Click(object sender, EventArgs e)

// Make sure we have some selected entries.


int cnt = listView1.SelectedIndices.Count;
if (cnt == 0 )
{
MessageBox.Show("Oops, no files to remove...", "C1Zip");
return;
}
// Confirm with user.
DialogResult dr;
string

msg;

msg = "Please confirm that you want to delete " + cnt.ToString() + "
entries.";
dr = MessageBox.Show(msg, "C1Zip", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question);
if (dr != DialogResult.OK) return;
// Delete all selected entries.
foreach (ListViewItem lvi in listView1.SelectedItems)
{
C1ZipEntry ze = (C1ZipEntry)lvi.Tag;
if (ze.SizeCompressed > 0)
{
m_Zip.Entries.Remove(ze.FileName);
}
}
// Done.
UpdateDisplay();
}
The most important line calls the Remove method on the Entries property of the C1ZipFile
object. The parameter is the string that contains the file name of the entry (which is stored in
the entry's FileName property).
This concludes the Handling Zip Files tutorial.

Zip for .NET Frequently Asked


Questions
Here are some frequently asked questions (FAQs) about Zip for .NET:
How much data can be stored in a ZIP file comment? I would like to use it to store information
in XML.
They are limited to 32k. However, if you are going anywhere near that value, it would be better
to add that information as a separate file instead.
What is the maximum number of files that can be stored in a ZIP file?
Same limit, 32k entries. The total length of the zip file is limited to 4 gigs. All these limits are
related to the types of variables used in the zip file specification. Interestingly, there's a
proposed spec for 64-bit extensions to the zip format, but that's not widely used yet, and there
is a lot of debate still going on.
For more FAQs about C1Zip, visit ComponentOne.

API Reference
The following topics contain the API reference for Zip for .NET.

See Also
C1.C1Zip.4 Assembly

C1.C1Zip.4 Assembly
Namespaces
C1.C1Zip Namespace
Overview
Classes

Class

Description

C1ZipEntry

Represents an entry in a zip file, and exposes information including


the entry name, compressed and uncompressed sizes, date,
checksum, etc.

C1ZipEntryCollection A collection of C1ZipEntry objects that represent the contents of a


zip file.
C1ZipFile

Used for creating, opening, and managing zip files.

C1ZStreamReader

Decompresses data from .NET streams.

C1ZStreamWriter

Compresses data into .NET Streams.

ZipFileException

Exception thrown when trying to open an invalid Zip file.

ZipProgressEventArgs Provides data for the C1ZipFile.Progress event of a C1ZipFile.

Delegates
Delegate

Description

ZipProgressEventHandler Represents the method that will handle the C1ZipFile.Progress


event of a C1ZipFile.

Enumerations
Enumeration

Description

CompressionLevelEnum Specifies the level of compression to be applied when adding


entries to a C1ZipFile.

See Also
Reference
C1.C1Zip.4 Assembly

Classes
C1ZipEntry
Represents an entry in a zip file, and exposes information including the entry name, compressed
and uncompressed sizes, date, checksum, etc.

Object Model

Syntax
Visual Basic (Declaration)
Public Class C1ZipEntry
C#
public class C1ZipEntry

Inheritance Hierarchy
System.Object
C1.C1Zip.C1ZipEntry

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntry Members
C1.C1Zip Namespace

Overview
Represents an entry in a zip file, and exposes information including the entry name, compressed
and uncompressed sizes, date, checksum, etc.

Object Model

Syntax
Visual Basic (Declaration)
Public Class C1ZipEntry
C#
public class C1ZipEntry

Inheritance Hierarchy
System.Object
C1.C1Zip.C1ZipEntry

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntry Members
C1.C1Zip Namespace

Members
Properties Methods

The following tables list the members exposed by C1ZipEntry.

Public Properties
Name

Description

Attributes

Gets the file attributes associated with the entry.

Comment

Gets or sets a comment associated with the entry.

CRC32

Gets the checksum calculated when the entry was compressed.

Date

Gets the date and time when the file used to create the entry was

last modified.
FileName

Gets the entry name. This is usually a file name, optionally


including a path.

IsEncrypted

Gets a value that determines whether the entry is encrypted.

SizeCompressed

Gets the compressed size of the entry, in bytes.

SizeCompressedLong

Gets the compressed size of the entry, in bytes, as a long integer.

SizeUncompressed

Gets the original (uncompressed) size of the entry, in bytes.

SizeUncompressedLong Gets the original (uncompressed) size of the entry, in bytes, as a


long integer.
Top

Public Methods
Name

Description

CheckCRC32

Calculates a checksum value for the entry and compares it to the


checksum that was stored when the entry was created.

CheckPassword

Checks whether this C1ZipEntry can be read with the currently set
password.

Extract

Extracts this entry to a file.

OpenReader

Returns a System.IO.Stream that can be used to read the content of the


entry without extracting it to a disk file.

Remove
Top

See Also
Reference

Removes this entry from the zip file.

C1ZipEntry Class
C1.C1Zip Namespace

Methods
%%scrap%%
" -->
For a list of all members of this type, see C1ZipEntry members.

Public Methods
Name

Description

CheckCRC32

Calculates a checksum value for the entry and compares it to the


checksum that was stored when the entry was created.

CheckPassword

Checks whether this C1ZipEntry can be read with the currently set
password.

Extract

Extracts this entry to a file.

OpenReader

Returns a System.IO.Stream that can be used to read the content of the


entry without extracting it to a disk file.

Remove

Removes this entry from the zip file.

Top

See Also
Reference
C1ZipEntry Class
C1.C1Zip Namespace

CheckCRC32 Method
Calculates a checksum value for the entry and compares it to the checksum that was stored
when the entry was created.

Syntax
Visual Basic (Declaration)

Public Function CheckCRC32() As Boolean


C#
public bool CheckCRC32()

Return Value
True if the checksum values match, false otherwise.

Remarks
This method is used to check the integrity of the entries in the zip file. If the calculated
checksum does not match the stored checksum, then either the zip file is corrupted or the
program used to create the zip file is incompatible with C1Zip.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntry Class
C1ZipEntry Members

CheckPassword Method
Checks whether this C1ZipEntry can be read with the currently set password.

Syntax
Visual Basic (Declaration)
Public Function CheckPassword() As Boolean
C#
public bool CheckPassword()

Return Value
True if the entry can be read with the current password, or if the entry is not encrypted.

Remarks

This method is more efficient than using a try/catch block and trying to open the entry to
determine whether the current password is valid for the entry.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntry Class
C1ZipEntry Members

Extract Method
Name and location of the extracted file.
Extracts this entry to a file.

Syntax
Visual Basic (Declaration)
Public Sub Extract( _
ByVal destFileName As String _
)
C#
public void Extract(
string destFileName
)

Parameters
destFileName
Name and location of the extracted file.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also

Reference
C1ZipEntry Class
C1ZipEntry Members

OpenReader Method
Returns a System.IO.Stream that can be used to read the content of the entry without extracting
it to a disk file.

Syntax
Visual Basic (Declaration)
Public Function OpenReader() As Stream
C#
public Stream OpenReader()

Return Value
A System.IO.Stream that can be used to read the data in the entry.

Remarks
The System.IO.Stream returned is a C1ZStreamReader, which decompresses the data as it is
read from the entry.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntry Class
C1ZipEntry Members

Remove Method
Removes this entry from the zip file.

Syntax
Visual Basic (Declaration)

Public Sub Remove()


C#
public void Remove()

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntry Class
C1ZipEntry Members

Properties
>
Name

Description

Attributes

Gets the file attributes associated with the entry.

Comment

Gets or sets a comment associated with the entry.

CRC32

Gets the checksum calculated when the entry was compressed.

Date

FileName

Gets the date and time when the file used to create the entry was
last modified.
Gets the entry name. This is usually a file name, optionally including
a path.

IsEncrypted

Gets a value that determines whether the entry is encrypted.

SizeCompressed

Gets the compressed size of the entry, in bytes.

SizeCompressedLong

Gets the compressed size of the entry, in bytes, as a long integer.

SizeUncompressed

Gets the original (uncompressed) size of the entry, in bytes.

SizeUncompressedLong

Gets the original (uncompressed) size of the entry, in bytes, as a


long integer.

Top

See Also
Reference
C1ZipEntry Class
C1.C1Zip Namespace

Attributes Property
Gets the file attributes associated with the entry.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property Attributes As FileAttributes
C#
public FileAttributes Attributes {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntry Class
C1ZipEntry Members

Comment Property
Gets or sets a comment associated with the entry.

Syntax
Visual Basic (Declaration)
Public Property Comment As String
C#
public string Comment {get; set;}

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntry Class
C1ZipEntry Members

CRC32 Property
Gets the checksum calculated when the entry was compressed.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property CRC32 As Integer
C#
public int CRC32 {get;}

Remarks
This value can be used to check the integrity of the entry when it is decompressed.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntry Class
C1ZipEntry Members

Date Property
Gets the date and time when the file used to create the entry was last modified.

Syntax

Visual Basic (Declaration)


Public ReadOnly Property Date As Date
C#
public DateTime Date {get;}

Remarks
This value can be used to check whether an entry needs to be updated because the source file
was modified since it was last compressed.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntry Class
C1ZipEntry Members

FileName Property
Gets the entry name. This is usually a file name, optionally including a path.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property FileName As String
C#
public string FileName {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also

Reference
C1ZipEntry Class
C1ZipEntry Members

IsEncrypted Property
Gets a value that determines whether the entry is encrypted.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property IsEncrypted As Boolean
C#
public bool IsEncrypted {get;}

Remarks
Encrypted entries can only be extracted if the C1ZipFile.Password property on the containing
C1ZipFile object is set to the password that was used when the file was added to the zip file.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntry Class
C1ZipEntry Members

SizeCompressed Property
Gets the compressed size of the entry, in bytes.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property SizeCompressed As Integer
C#

public int SizeCompressed {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntry Class
C1ZipEntry Members

SizeCompressedLong Property
Gets the compressed size of the entry, in bytes, as a long integer.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property SizeCompressedLong As Long
C#
public long SizeCompressedLong {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntry Class
C1ZipEntry Members

SizeUncompressed Property
Gets the original (uncompressed) size of the entry, in bytes.

Syntax

Visual Basic (Declaration)


Public ReadOnly Property SizeUncompressed As Integer
C#
public int SizeUncompressed {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntry Class
C1ZipEntry Members

SizeUncompressedLong Property
Gets the original (uncompressed) size of the entry, in bytes, as a long integer.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property SizeUncompressedLong As Long
C#
public long SizeUncompressedLong {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntry Class
C1ZipEntry Members

C1ZipEntryCollection
A collection of C1ZipEntry objects that represent the contents of a zip file.

Object Model

Syntax
Visual Basic (Declaration)
Public Class C1ZipEntryCollection
C#
public class C1ZipEntryCollection

Remarks
Use the C1ZipEntryCollection to programmatically manage the contents of zip files. You can
add, remove, extract, or insert items into the C1ZipEntryCollection.

Inheritance Hierarchy
System.Object
C1.C1Zip.C1ZipEntryCollection

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Members
C1.C1Zip Namespace

Overview
A collection of C1ZipEntry objects that represent the contents of a zip file.

Object Model

Syntax
Visual Basic (Declaration)
Public Class C1ZipEntryCollection
C#
public class C1ZipEntryCollection

Remarks
Use the C1ZipEntryCollection to programmatically manage the contents of zip files. You can
add, remove, extract, or insert items into the C1ZipEntryCollection.

Inheritance Hierarchy
System.Object
C1.C1Zip.C1ZipEntryCollection

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Members
C1.C1Zip Namespace

Members
For internal use only.

Syntax
Visual Basic (Declaration)
Public Shadows ReadOnly Property Items As
System.Windows.Forms.ListView.ListViewItemCollection

C#
public new System.Windows.Forms.ListView.ListViewItemCollection Items {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1PreviewThumbnailView Class
C1PreviewThumbnailView Members

Methods
%%scrap%%
" -->
For a list of all members of this type, see C1ZipEntryCollection members.

Public Methods
Name

Description

Add

Overloaded. Adds an entry to the current zip file.

AddFolder

Overloaded. Adds the content of a folder to the current zip file.

Contains

Overloaded. Determines whether the collection contains an entry with a


given name.

Extract

Overloaded. Extracts a file from the current zip file.

ExtractFolder

Extracts the contents of the zip file into a specified path.

IndexOf

Overloaded. Gets the index of the entry with the specified name.

OpenWriter

Overloaded. Opens a stream for writing an entry into the zip file.

Remove

Overloaded. Removes an entry from the current zip file.

Top

See Also
Reference
C1ZipEntryCollection Class
C1.C1Zip Namespace

Add Method
Adds an entry to the current zip file.

Overload List
Overload

Description

Add(String)

Adds an entry to the current zip file.

Add(String[])

Adds a list of entries to the current zip file.

Add(String,Int32)

Adds an entry to the current zip file.

Add(String,String)

Adds an entry to the current zip file.

Add(String,String,DateTime)

Adds an entry to the current zip file.

Add(Stream,String)

Adds a stream to the current zip file.

Add(Stream,String,DateTime) Adds a stream to the current zip file.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members

Add(String) Method
Name of the file to add to the zip file.
Adds an entry to the current zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Sub Add( _
ByVal fileName As String _
)
C#
public void Add(
string fileName
)

Parameters
fileName
Name of the file to add to the zip file.

Remarks
By default, the directory name is not stored in the zip file. To store a specific part of the
directory name in the zip file, use the overloaded version of the Add method with a
pathLevels parameter.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

Add(String[]) Method
Array containing the file names of the entries to be added to the zip file.

Adds a list of entries to the current zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Sub Add( _
ByVal fileNames() As String _
)
C#
public void Add(
string[] fileNames
)

Parameters
fileNames
Array containing the file names of the entries to be added to the zip file.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

Add(String,Int32) Method
Name of the file to add to the zip file.
The number of path levels to be stored as the entry name.
Adds an entry to the current zip file.

Syntax
Visual Basic (Declaration)

Public Overloads Sub Add( _


ByVal fileName As String, _
ByVal pathLevels As Integer _
)
C#
public void Add(
string fileName,
int pathLevels
)

Parameters
fileName
Name of the file to add to the zip file.
pathLevels
The number of path levels to be stored as the entry name.

Remarks
By default, path names are not stored in the zip file. For example, adding the file
"c:\temp\samples\readme.txt" to the zip file will create an entry called "readme.txt".
The pathLevels parameter allows you to store one or more levels of the path in the
entry name. For example, adding the file "c:\temp\samples\readme.txt" to the zip file
with pathLevels=1 will create an entry called "samples\readme.txt".

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

Add(String,String) Method
Name of the file to add to the zip file.
Name of the new entry as stored in the zip file.

Adds an entry to the current zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Sub Add( _
ByVal fileName As String, _
ByVal entryName As String _
)
C#
public void Add(
string fileName,
string entryName
)

Parameters
fileName
Name of the file to add to the zip file.
entryName
Name of the new entry as stored in the zip file.

Remarks
By default, entries in the zip file have the same name as the original (uncompressed)
file. This method allows you to specify a different name, including a path for
example.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

Add(String,String,DateTime) Method
Name of the file to add to the zip file.
Name of the new entry as stored in the zip file.
The date and time when the file was last modified.
Adds an entry to the current zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Sub Add( _
ByVal fileName As String, _
ByVal entryName As String, _
ByVal dateTime As Date _
)
C#
public void Add(
string fileName,
string entryName,
DateTime dateTime
)

Parameters
fileName
Name of the file to add to the zip file.
entryName
Name of the new entry as stored in the zip file.
dateTime
The date and time when the file was last modified.

Remarks
By default, entries in the zip file have the same name as the original
(uncompressed) file. This method allows you to specify a different name,
including a path for example.

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,


Windows Server 2008 (Server Core not supported), Windows Server 2008 R2
(Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

Add(Stream,String) Method
Stream that contains data for the new entry.
Name to be used for the new entry.
Adds a stream to the current zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Sub Add( _
ByVal stream As Stream, _
ByVal entryName As String _
)
C#
public void Add(
Stream stream,
string entryName
)

Parameters
stream
Stream that contains data for the new entry.
entryName
Name to be used for the new entry.

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,


Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

Add(Stream,String,DateTime) Method
Stream that contains data for the new entry.
Name to be used for the new entry.
The date and time when the file was last modified.
Adds a stream to the current zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Sub Add( _
ByVal stream As Stream, _
ByVal entryName As String, _
ByVal dateTime As Date _
)
C#
public void Add(
Stream stream,
string entryName,
DateTime dateTime
)

Parameters
stream
Stream that contains data for the new entry.
entryName
Name to be used for the new entry.

dateTime
The date and time when the file was last modified.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2
(Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

AddFolder Method
Adds the content of a folder to the current zip file.

Overload List
Overload

Description

AddFolder(String)

Adds the content of a folder to the current zip file.

AddFolder(String,String)

Adds the content of a folder to the current zip file.

AddFolder(String,String,Boolean) Adds the content of a folder to the current zip file.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members

AddFolder(String) Method
The full path of the folder to be added to the zip file.

Adds the content of a folder to the current zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Sub AddFolder( _
ByVal path As String _
)
C#
public void AddFolder(
string path
)

Parameters
path
The full path of the folder to be added to the zip file.

Remarks
This method adds all files and sub folders to the zip file.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

AddFolder(String,String) Method
The full path of the folder to be added to the zip file.
A mask that specifies which files to add.
Adds the content of a folder to the current zip file.

Syntax

Visual Basic (Declaration)


Public Overloads Sub AddFolder( _
ByVal path As String, _
ByVal searchPattern As String _
)
C#
public void AddFolder(
string path,
string searchPattern
)

Parameters
path
The full path of the folder to be added to the zip file.
searchPattern
A mask that specifies which files to add.

Remarks
If the folder contains sub folders, those are also added to the zip file.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

AddFolder(String,String,Boolean) Method
The full path of the folder to be added to the zip file.
A mask that specifies which files to add.
True to include sub folders, false to include only files at the root level.

Adds the content of a folder to the current zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Sub AddFolder( _
ByVal path As String, _
ByVal searchPattern As String, _
ByVal includeSubfolders As Boolean _
)
C#
public void AddFolder(
string path,
string searchPattern,
bool includeSubfolders
)

Parameters
path
The full path of the folder to be added to the zip file.
searchPattern
A mask that specifies which files to add.
includeSubfolders
True to include sub folders, false to include only files at the root level.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2
(Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

Contains Method
Determines whether the collection contains an entry with a given name.

Overload List
Overload

Description

Contains(String)

Determines whether the collection contains an entry with a given name.

Contains(C1ZipEntry) Determines whether the collection contains an entry.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members

Contains(String) Method
Name of the entry to look for.
Determines whether the collection contains an entry with a given name.

Syntax
Visual Basic (Declaration)
Public Overloads Function Contains( _
ByVal name As String _
) As Boolean
C#
public bool Contains(
string name
)

Parameters
name

Name of the entry to look for.

Return Value
True if the collection contains an entry with the given name, false otherwise.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

Contains(C1ZipEntry) Method
Entry of the entry to look for.
Determines whether the collection contains an entry.

Syntax
Visual Basic (Declaration)
Public Overloads Function Contains( _
ByVal entry As C1ZipEntry _
) As Boolean
C#
public bool Contains(
C1ZipEntry entry
)

Parameters
entry
Entry of the entry to look for.

Return Value
True if the collection contains the entry, false otherwise.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

Extract Method
Extracts a file from the current zip file.

Overload List
Overload

Description

Extract(Int32,String) Extracts a file from the current zip file.


Extract(String,String) Extracts a file from the current zip file.
Extract(Int32)

Extracts a file from the current zip file.

Extract(String)

Extracts a file from the current zip file.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members

Extract(Int32,String) Method
Index of the entry to extract.

Name and location of the extracted file.


Extracts a file from the current zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Sub Extract( _
ByVal index As Integer, _
ByVal destFileName As String _
)
C#
public void Extract(
int index,
string destFileName
)

Parameters
index
Index of the entry to extract.
destFileName
Name and location of the extracted file.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

Extract(String,String) Method
Name of the entry to extract.
Name and location of the extracted file.

Extracts a file from the current zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Sub Extract( _
ByVal entryName As String, _
ByVal destFileName As String _
)
C#
public void Extract(
string entryName,
string destFileName
)

Parameters
entryName
Name of the entry to extract.
destFileName
Name and location of the extracted file.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

Extract(Int32) Method
The toolstrip to attach to.
Attaches the tools integrator to the specified toolstrip. If the toolstrip contains preview items,
they will be handled by the tools integrator.

Syntax
Visual Basic (Declaration)
Public Sub AttachToolStrip( _
ByVal toolstrip As System.Windows.Forms.ToolStrip _
)
C#
public void AttachToolStrip(
System.Windows.Forms.ToolStrip toolstrip
)

Parameters
toolstrip
The toolstrip to attach to.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1PreviewToolsIntegrator Class
C1PreviewToolsIntegrator Members

Extract(String) Method
Name of the entry to extract.
Extracts a file from the current zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Sub Extract( _
ByVal entryName As String _
)
C#

public void Extract(


string entryName
)

Parameters
entryName
Name of the entry to extract.

Remarks
The entry is extracted to a file in the same folder as the current zip file, with the same
name as the entry.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

ExtractFolder Method
Destination path for the unzipped files.
Extracts the contents of the zip file into a specified path.

Syntax
Visual Basic (Declaration)
Public Sub ExtractFolder( _
ByVal path As String _
)
C#
public void ExtractFolder(
string path
)

Parameters
path
Destination path for the unzipped files.

Remarks
If the zip file contains compressed folders, new folders will be created under the
destination path to preserve the hierarchical structure of the archive.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members

IndexOf Method
Gets the index of the entry with the specified name.

Overload List
Overload

Description

IndexOf(String)

Gets the index of the entry with the specified name.

IndexOf(C1ZipEntry) Gets the index of an entry in the collection.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference

C1ZipEntryCollection Class
C1ZipEntryCollection Members

IndexOf(String) Method
Name of the entry to look for.
Gets the index of the entry with the specified name.

Syntax
Visual Basic (Declaration)
Public Overloads Function IndexOf( _
ByVal name As String _
) As Integer
C#
public int IndexOf(
string name
)

Parameters
name
Name of the entry to look for.

Return Value
The index of the entry in the collection, or -1 if the entry was not found.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

IndexOf(C1ZipEntry) Method
C1ZipEntry to look for.

Gets the index of an entry in the collection.

Syntax
Visual Basic (Declaration)
Public Overloads Function IndexOf( _
ByVal entry As C1ZipEntry _
) As Integer
C#
public int IndexOf(
C1ZipEntry entry
)

Parameters
entry
C1ZipEntry to look for.

Return Value
The index of the entry in the collection, or -1 if the entry was not found.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

OpenWriter Method
For internal use.

Overload List
Overload

Description

FileSave()

For internal use.

FileSave(String,ExportProvider) For internal use.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1PreviewToolsIntegrator Class
C1PreviewToolsIntegrator Members

OpenWriter(String,Boolean) Method
The name of the new entry.
Whether to use a memory stream or temporary file.
Opens a stream for writing an entry into the zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Function OpenWriter( _
ByVal entryName As String, _
ByVal useMemory As Boolean _
) As Stream
C#
public Stream OpenWriter(
string entryName,
bool useMemory
)

Parameters
entryName
The name of the new entry.
useMemory

Whether to use a memory stream or temporary file.

Return Value
A stream that can be used to write data into the zip file. The entry is not added until
the stream is closed.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

OpenWriter(String,DateTime,Boolean) Method
The name of the new entry.
The date and time when the file was last modified.
Whether to use a memory stream or temporary file.
Opens a stream for writing an entry into the zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Function OpenWriter( _
ByVal entryName As String, _
ByVal dateTime As Date, _
ByVal useMemory As Boolean _
) As Stream
C#
public Stream OpenWriter(
string entryName,
DateTime dateTime,
bool useMemory
)

Parameters
entryName
The name of the new entry.
dateTime
The date and time when the file was last modified.
useMemory
Whether to use a memory stream or temporary file.

Return Value
A stream that can be used to write data into the zip file. The entry is not added
until the stream is closed.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2
(Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

Remove Method
Removes an entry from the current zip file.

Overload List
Overload

Description

Remove(Int32)

Removes an entry from the current zip file.

Remove(String)

Removes an entry from the current zip file.

Remove(Int32[])

Removes several entries from the current zip file.

Remove(String[])

Removes several entries from the current zip file.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members

Remove(Int32) Method
Index of the entry to remove.
Removes an entry from the current zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Sub Remove( _
ByVal index As Integer _
)
C#
public void Remove(
int index
)

Parameters
index
Index of the entry to remove.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also

Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

Remove(String) Method
Name of the entry to remove (case-insensitive).
Removes an entry from the current zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Sub Remove( _
ByVal fileName As String _
)
C#
public void Remove(
string fileName
)

Parameters
fileName
Name of the entry to remove (case-insensitive).

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

Remove(Int32[]) Method
Array containing the indices of the entries to remove.
Removes several entries from the current zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Sub Remove( _
ByVal indices() As Integer _
)
C#
public void Remove(
int[] indices
)

Parameters
indices
Array containing the indices of the entries to remove.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

Remove(String[]) Method
Array containing the names of the entries to remove.
Removes several entries from the current zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Sub Remove( _
ByVal entryNames() As String _
)

C#
public void Remove(
string[] entryNames
)

Parameters
entryNames
Array containing the names of the entries to remove.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

Properties
>
Name

Description

Count

Gets the number of entries in the current zip file.

Item

Overloaded. Gets the C1ZipEntry at the specified index.

Top

See Also
Reference
C1ZipEntryCollection Class
C1.C1Zip Namespace

Count Property
Gets the number of entries in the current zip file.

Syntax

Visual Basic (Declaration)


Public ReadOnly Property Count As Integer
C#
public int Count {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members

Item Property
Gets the C1ZipEntry at the specified index.

Overload List
Overload

Description

Item(Int32)

Gets the C1ZipEntry at the specified index.

Item(String)

Gets the C1ZipEntry with the given name (returns null if the entry cannot be
found).

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members

Item(Int32) Property
Gets the C1ZipEntry at the specified index.

Syntax
Visual Basic (Declaration)
Public Overloads ReadOnly Property Item( _
ByVal index As Integer _
) As C1ZipEntry
C#
public C1ZipEntry Item(
int index
) {get;}

Parameters
index

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

Item(String) Property
Gets the C1ZipEntry with the given name (returns null if the entry cannot be found).

Syntax
Visual Basic (Declaration)
Public Overloads ReadOnly Property Item( _
ByVal name As String _
) As C1ZipEntry

C#
public C1ZipEntry Item(
string name
) {get;}

Parameters
name

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipEntryCollection Class
C1ZipEntryCollection Members
Overload List

C1ZipFile
Example

Used for creating, opening, and managing zip files.

Object Model

Syntax
Visual Basic (Declaration)
Public Class C1ZipFile
C#
public class C1ZipFile

Remarks

Use the Open(String) or Create(String) methods to associate the C1Zip file object with a zip file
on disk. Then use the Entries property to add, remove, retrieve, or inspect individual entries in
the zip file.
C1ZipFile can only be used with standard zip files. The component does not support other
similar formats such as gzip, zip2, tar, or rar.
The standard zip file imposes some limitations on the size of each entry. You cannot use it to
compress files larger than 4 gigabytes (uint.MaxValue).

Example
The code below creates a zip file called sources.zip and adds all files with a "cs" extension to
the zip file:

C#

// get path for zip file and files to compress


string path = Application.ExecutablePath;
int pos = path.IndexOf(@"\bin");
path = path.Substring(0, pos + 1);
// create a zip file
C1ZipFile zip = new C1ZipFile();
zip.Create(path + "source.zip");
// add all files with extension cs to the zip file
foreach (string fileName in Directory.GetFiles(path, "*.cs"))
zip.Entries.Add(fileName);
// show result
foreach (C1ZipEntry ze in zip.Entries)
{
Console.WriteLine("{0} {1:#,##0} {2:#,##0}",
ze.FileName, ze.SizeUncompressed, ze.SizeCompressed);
}

Inheritance Hierarchy
System.Object
C1.C1Zip.C1ZipFile

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference

C1ZipFile Members
C1.C1Zip Namespace

Overview
Example

Used for creating, opening, and managing zip files.

Object Model

Syntax
Visual Basic (Declaration)
Public Class C1ZipFile
C#
public class C1ZipFile

Remarks
Use the Open(String) or Create(String) methods to associate the C1Zip file object with a zip file
on disk. Then use the Entries property to add, remove, retrieve, or inspect individual entries in
the zip file.
C1ZipFile can only be used with standard zip files. The component does not support other
similar formats such as gzip, zip2, tar, or rar.
The standard zip file imposes some limitations on the size of each entry. You cannot use it to
compress files larger than 4 gigabytes (uint.MaxValue).

Example
The code below creates a zip file called sources.zip and adds all files with a "cs" extension to
the zip file:

C#

// get path for zip file and files to compress


string path = Application.ExecutablePath;
int pos = path.IndexOf(@"\bin");
path = path.Substring(0, pos + 1);
// create a zip file
C1ZipFile zip = new C1ZipFile();
zip.Create(path + "source.zip");

// add all files with extension cs to the zip file


foreach (string fileName in Directory.GetFiles(path, "*.cs"))
zip.Entries.Add(fileName);
// show result
foreach (C1ZipEntry ze in zip.Entries)
{
Console.WriteLine("{0} {1:#,##0} {2:#,##0}",
ze.FileName, ze.SizeUncompressed, ze.SizeCompressed);
}

Inheritance Hierarchy
System.Object
C1.C1Zip.C1ZipFile

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Members
C1.C1Zip Namespace

Members
Properties Methods Events

The following tables list the members exposed by C1ZipFile.

Public Constructors
Name

Description

C1ZipFile Constructor Overloaded.


Top

Public Properties
Name

Description

Comment

Gets or sets a comment associated with the current zip file.

CompressionLevel

Gets or sets the compression level to use when adding entries to the
zip file.

Entries

Gets a C1ZipEntryCollection that contains the entries in the zip file.

FileName

Gets the name of the current zip file.

MemoryThreshold

Gets or sets the size of the largest stream to be compressed in


memory.

OverwriteHidden

Determines whether the component should overwrite hidden files


when extracting entries from the zip file.

OverwriteReadOnly Determines whether the component should overwrite read-only files


when extracting entries from the zip file.
OverwriteSystem

Determines whether the component should overwrite system files


when extracting entries from the zip file.

Password

Gets or sets the password to use when adding or retrieving entries


from the zip file.

TempFileName

Gets or sets the name of the temporary file to use when adding entries
to the zip file.

UseUtf8Encoding

Determines whether file names and comments should be stored in


UTF8 format.

Top

Public Methods
Name

Description

Close

Resets all data members of the C1ZipFile object.

CloseBatch

Closes a zip file after it was opened with a call to the OpenBatch
method.

Create

Overloaded. Creates an empty zip file on disk.

IsZipFile

Overloaded. Tests whether a file is a valid zip file.

Open

Overloaded. Opens an existing zip file.

OpenBatch

Opens the zip file for multiple operations.

Refresh

Refreshes all data members by re-opening the current zip file.

Top

Public Events
Name

Description

Progress

Fired while data is being read from or written into a zip file.

Top

See Also
Reference
C1ZipFile Class
C1.C1Zip Namespace

C1ZipFile Constructor

Overload List
Overload

Description

C1ZipFile Constructor()

Initializes a new instance of the C1ZipFile class.

C1ZipFile Constructor(String,Boolean)

Initializes a new instance of the C1ZipFile class and


creates or opens a zip file associated with this new
instance.

C1ZipFile Constructor(String)

Initializes a new instance of the C1ZipFile class and


opens a zip file associated with this new instance.

C1ZipFile Constructor(Stream,Boolean) Initializes a new instance of the C1ZipFile class and


opens a zip stream associated with this new instance.
C1ZipFile Constructor(Stream)

Initializes a new instance of the C1ZipFile class and


opens a zip stream associated with this new instance.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

C1ZipFile Constructor()
Initializes a new instance of the C1ZipFile class.

Syntax
Visual Basic (Declaration)
Public Function New()
C#
public C1ZipFile()

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members
Overload List

C1ZipFile Constructor(String,Boolean)
The name of the zip file to open or create.
True to create a new zip file, false to open an existing file.
Initializes a new instance of the C1ZipFile class and creates or opens a zip file associated with
this new instance.

Syntax
Visual Basic (Declaration)
Public Function New( _
ByVal fileName As String, _
ByVal create As Boolean _
)
C#
public C1ZipFile(
string fileName,
bool create
)

Parameters
fileName
The name of the zip file to open or create.
create
True to create a new zip file, false to open an existing file.

Remarks
If create is true and the zip file already exists, it is overwritten with a new empty file.
If create is false and the zip file already exists, the existing file is opened.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference
C1ZipFile Class
C1ZipFile Members
Overload List

C1ZipFile Constructor(String)
The name of the zip file to open.
Initializes a new instance of the C1ZipFile class and opens a zip file associated with this new
instance.

Syntax
Visual Basic (Declaration)
Public Function New( _
ByVal fileName As String _
)
C#
public C1ZipFile(
string fileName
)

Parameters
fileName
The name of the zip file to open.

Remarks
If the file does not exist, a new empty file is created.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference

C1ZipFile Class
C1ZipFile Members
Overload List

C1ZipFile Constructor(Stream,Boolean)
System.IO.Stream that contains the zip data.
Whether to initialize the stream with an empty zip header or open an existing zip file in the
stream.
Initializes a new instance of the C1ZipFile class and opens a zip stream associated with this new
instance.

Syntax
Visual Basic (Declaration)
Public Function New( _
ByVal stream As Stream, _
ByVal create As Boolean _
)
C#
public C1ZipFile(
Stream stream,
bool create
)

Parameters
stream
System.IO.Stream that contains the zip data.
create
Whether to initialize the stream with an empty zip header or open an existing zip file in
the stream.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference
C1ZipFile Class
C1ZipFile Members
Overload List

C1ZipFile Constructor(Stream)
System.IO.Stream that contains the zip data.
Initializes a new instance of the C1ZipFile class and opens a zip stream associated with this new
instance.

Syntax
Visual Basic (Declaration)
Public Function New( _
ByVal stream As Stream _
)
C#
public C1ZipFile(
Stream stream
)

Parameters
stream
System.IO.Stream that contains the zip data.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members
Overload List

Methods
%%scrap%%

" -->
For a list of all members of this type, see C1ZipFile members.

Public Methods
Name

Description

Close

Resets all data members of the C1ZipFile object.

CloseBatch

Closes a zip file after it was opened with a call to the OpenBatch
method.

Create

Overloaded. Creates an empty zip file on disk.

IsZipFile

Overloaded. Tests whether a file is a valid zip file.

Open

Overloaded. Opens an existing zip file.

OpenBatch

Opens the zip file for multiple operations.

Refresh

Refreshes all data members by re-opening the current zip file.

Top

See Also
Reference
C1ZipFile Class
C1.C1Zip Namespace

Close Method
Resets all data members of the C1ZipFile object.

Syntax
Visual Basic (Declaration)
Public Sub Close()
C#
public void Close()

Remarks
Disk files are automatically closed by C1Zip. You only need to use this method if you want to
break the connection between a C1ZipFile class and a physical zip file.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

CloseBatch Method
Closes a zip file after it was opened with a call to the OpenBatch method.

Syntax
Visual Basic (Declaration)
Public Sub CloseBatch()
C#
public void CloseBatch()

Remarks
See the OpenBatch method for a complete description and a sample.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

Create Method
Creates an empty zip file on disk.

Overload List
Overload

Description

Create(String)

Creates an empty zip file on disk.

Create(Stream)

Creates a new zip file in a stream.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

Create(String) Method
The name of the zip file to create, including the path.
Creates an empty zip file on disk.

Syntax
Visual Basic (Declaration)
Public Overloads Sub Create( _
ByVal fileName As String _
)
C#
public void Create(
string fileName
)

Parameters
fileName

The name of the zip file to create, including the path.

Remarks
If a file by the same name already exists, it is deleted before the new one is created.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members
Overload List

Create(Stream) Method
Example

System.IO.Stream that will contain the new zip file.


Creates a new zip file in a stream.

Syntax
Visual Basic (Declaration)
Public Overloads Sub Create( _
ByVal stream As Stream _
)
C#
public void Create(
Stream stream
)

Parameters
stream
System.IO.Stream that will contain the new zip file.

Example

The code below creates a new C1ZipFile on a memory stream, then adds several files to it.
Finally, the code gets the zipped data out as an array of bytes, which could be stored in a
database for example.

C#

// create zip on a stream


MemoryStream msZip = new MemoryStream();
C1ZipFile zip = new C1ZipFile(msZip, true);
// add some entries to it
foreach (string f in Directory.GetFiles(@"c:\WINDOWS\Web\Wallpaper"))
{
zip.Entries.Add(f);
}
// get zipped data out as a byte array
byte[] zipData = msZip.ToArray();

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members
Overload List

IsZipFile Method
Tests whether a file is a valid zip file.

Overload List
Overload

Description

IsZipFile(String)

Tests whether a file is a valid zip file.

IsZipFile(Stream)

Tests whether a stream contains a valid zip file.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

IsZipFile(String) Method
Name of the file to test.
Tests whether a file is a valid zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Shared Function IsZipFile( _
ByVal fileName As String _
) As Boolean
C#
public static bool IsZipFile(
string fileName
)

Parameters
fileName
Name of the file to test.

Return Value
True if the file exists and is a valid zip file, false otherwise.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference

C1ZipFile Class
C1ZipFile Members
Overload List

IsZipFile(Stream) Method
System.IO.Stream to test.
Tests whether a stream contains a valid zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Shared Function IsZipFile( _
ByVal stream As Stream _
) As Boolean
C#
public static bool IsZipFile(
Stream stream
)

Parameters
stream
System.IO.Stream to test.

Return Value
True if stream contains a valid zip file, false otherwise.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members
Overload List

Open Method
Opens an existing zip file.

Overload List
Overload

Description

Open(String)

Opens an existing zip file.

Open(Stream)

Opens an existing zip file stored in a stream.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

Open(String) Method
The name of an existing zip file, including the path.
Opens an existing zip file.

Syntax
Visual Basic (Declaration)
Public Overloads Sub Open( _
ByVal fileName As String _
)
C#
public void Open(
string fileName
)

Parameters
fileName
The name of an existing zip file, including the path.

Remarks
This method checks that the zip file exists and is a valid zip file, then reads the zip file
directory into the Entries collection. The zip file is then closed, and can be used by other
applications. There is no need to close the zip file explicitly.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members
Overload List

Open(Stream) Method
Example

System.IO.Stream that contains a zip file.


Opens an existing zip file stored in a stream.

Syntax
Visual Basic (Declaration)
Public Overloads Sub Open( _
ByVal stream As Stream _
)
C#
public void Open(
Stream stream
)

Parameters
stream
System.IO.Stream that contains a zip file.

Remarks

This method allows you to open and work with a zip file stored in a stream instead of in an
actual file.
Typical usage scenarios for this are zip files stored as application resources or in binary
database fields.

Example
The example below loads information from a zip file stored in an embedded resource. To
embed a zip file in an application, follow these steps:
1) Right-click the project node in Visual Studio, select the Add | Add Existing Item...
menu option.
2) Select a zip file to add to the project as an embedded resource.
3) Select the newly added file and make sure the Build Action property is set to
"Embedded Resource".

C#

// get Stream from application resources


System.Reflection.Assembly a = this.GetType().Assembly;
using (Stream stream = a.GetManifestResourceStream("MyApp.test.zip"))
{
// open C1ZipFile on the stream
zip.Open(stream);
// enumerate the entries in the zip file,
foreach (C1ZipEntry ze in zip.Entries)
{
// show entries that have a 'txt' extension.
if (ze.FileName.ToLower().EndsWith(".txt"))
{
using (var sr = new StreamReader(ze.OpenReader()))
{
MessageBox.Show(sr.ReadToEnd(), ze.FileName);
}
}
}
}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference

C1ZipFile Class
C1ZipFile Members
Overload List

OpenBatch Method
Example

Opens the zip file for multiple operations.

Syntax
Visual Basic (Declaration)
Public Sub OpenBatch()
C#
public void OpenBatch()

Remarks
By default, C1ZipFile opens and closes the zip file automatically whenever entries are added or
removed.
This can cause delays in systems that have certain types of anti-virus software installed, or in
situations where you want to add a large number of relatively small entries. In these cases, use
the OpenBatch and CloseBatch methods to keep the zip file open until the entire operation is
concluded.
Use a finally clause to ensure that the CloseBatch method is called even if an exception occurs.

Example
The code below opens a zip file, adds several entries to it, then closes the file:

C#

C1ZipFile zip = new C1ZipFile();


zip.Open(myzipfile);
try
{
zip.OpenBatch();
foreach (string fileName in Directory.GetFiles(path, "*.*"))
zip.Entries.Add(fileName);
}
finally
{
zip.CloseBatch();
}

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

Refresh Method
Refreshes all data members by re-opening the current zip file.

Syntax
Visual Basic (Declaration)
Public Sub Refresh()
C#
public void Refresh()

Remarks
This method is useful in instances where other applications may have changed the zip file and
you want to make sure the information in the Entries collection is up to date.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

Properties
%%scrap%%
" -->
For a list of all members of this type, see C1ZipFile members.

Public Properties
Name

Description

Comment

Gets or sets a comment associated with the current zip file.

CompressionLevel

Gets or sets the compression level to use when adding entries to the
zip file.

Entries

Gets a C1ZipEntryCollection that contains the entries in the zip file.

FileName

Gets the name of the current zip file.

MemoryThreshold

Gets or sets the size of the largest stream to be compressed in


memory.

OverwriteHidden

Determines whether the component should overwrite hidden files


when extracting entries from the zip file.

OverwriteReadOnly Determines whether the component should overwrite read-only files


when extracting entries from the zip file.
OverwriteSystem

Determines whether the component should overwrite system files


when extracting entries from the zip file.

Password

Gets or sets the password to use when adding or retrieving entries


from the zip file.

TempFileName

Gets or sets the name of the temporary file to use when adding entries
to the zip file.

UseUtf8Encoding

Determines whether file names and comments should be stored in


UTF8 format.

Top

See Also
Reference

C1ZipFile Class
C1.C1Zip Namespace

Comment Property
Gets or sets a comment associated with the current zip file.

Syntax
Visual Basic (Declaration)
Public Property Comment As String
C#
public string Comment {get; set;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

CompressionLevel Property
Gets or sets the compression level to use when adding entries to the zip file.

Syntax
Visual Basic (Declaration)
Public Property CompressionLevel As CompressionLevelEnum
C#
public CompressionLevelEnum CompressionLevel {get; set;}

Remarks
Higher compression settings create smaller files, but take longer to process. The default setting
(CompressionLevelEnum.DefaultCompression) provides a good trade-off between compression
and speed.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

Entries Property
Gets a C1ZipEntryCollection that contains the entries in the zip file.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property Entries As C1ZipEntryCollection
C#
public C1ZipEntryCollection Entries {get;}

Remarks
The Entries collection is used to enumerate the entries in the zip file, and also to add, remove,
and expand entries.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

FileName Property
Gets the name of the current zip file.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property FileName As String
C#
public string FileName {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

MemoryThreshold Property
Gets or sets the size of the largest stream to be compressed in memory.

Syntax
Visual Basic (Declaration)
Public Property MemoryThreshold As Integer
C#
public int MemoryThreshold {get; set;}

Remarks
C1ZipFile compresses entries into temporary streams before adding them to the zip file.
Entries with fewer than MemoryThreshold bytes are compressed using a temporary memory
stream.
Entries with more than MemoryThreshold bytes are compressed using a temporary file. You can
control the location of the temporary file using the TempFileName property.

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

OverwriteHidden Property
Determines whether the component should overwrite hidden files when extracting entries from
the zip file.

Syntax
Visual Basic (Declaration)
Public Property OverwriteHidden As Boolean
C#
public bool OverwriteHidden {get; set;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

OverwriteReadOnly Property
Determines whether the component should overwrite read-only files when extracting entries
from the zip file.

Syntax
Visual Basic (Declaration)
Public Property OverwriteReadOnly As Boolean

C#
public bool OverwriteReadOnly {get; set;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

OverwriteSystem Property
Determines whether the component should overwrite system files when extracting entries from
the zip file.

Syntax
Visual Basic (Declaration)
Public Property OverwriteSystem As Boolean
C#
public bool OverwriteSystem {get; set;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

Password Property
Properties Methods Events

The following tables list the members exposed by C1PrintPreviewControl.

Public Constructors
Name

Description

C1PrintPreviewControl Constructor Initializes a new instance of the C1PrintPreviewControl


class.
Top

Public Properties
Name

Description

AccessibilityObject

(Inherited from System.Windows.Forms.Control)

AccessibleDefaultActionDescription (Inherited from System.Windows.Forms.Control)


AccessibleDescription

(Inherited from System.Windows.Forms.Control)

AccessibleName

(Inherited from System.Windows.Forms.Control)

AccessibleRole

(Inherited from System.Windows.Forms.Control)

ActiveControl

(Inherited from
System.Windows.Forms.ContainerControl)

AllowDrop

(Inherited from System.Windows.Forms.Control)

Anchor

(Inherited from System.Windows.Forms.Control)

AutoScaleDimensions

(Inherited from
System.Windows.Forms.ContainerControl)

AutoScaleMode

(Inherited from
System.Windows.Forms.ContainerControl)

AutoScrollOffset

(Inherited from System.Windows.Forms.Control)

AutoScrollPosition

(Inherited from

System.Windows.Forms.ScrollableControl)
AvailablePreviewActions

Gets or sets flags indicating which tools should be


available in the preview.

BindingContext

(Inherited from
System.Windows.Forms.ContainerControl)

Bottom

(Inherited from System.Windows.Forms.Control)

BottomToolStripPanel

For internal use.

BottomToolStripPanelVisible

For internal use.

Bounds

(Inherited from System.Windows.Forms.Control)

CanFocus

(Inherited from System.Windows.Forms.Control)

CanSelect

(Inherited from System.Windows.Forms.Control)

Capture

(Inherited from System.Windows.Forms.Control)

ClientRectangle

(Inherited from System.Windows.Forms.Control)

ClientSize

(Inherited from System.Windows.Forms.Control)

CompanyName

(Inherited from System.Windows.Forms.Control)

Container

(Inherited from System.ComponentModel.Component)

ContainsFocus

(Inherited from System.Windows.Forms.Control)

ContentPanel

For internal use.

ContextMenu

(Inherited from System.Windows.Forms.Control)

Created

(Inherited from System.Windows.Forms.Control)

CurrentAutoScaleDimensions

(Inherited from
System.Windows.Forms.ContainerControl)

DataBindings

(Inherited from System.Windows.Forms.Control)

DisplayRectangle

(Inherited from
System.Windows.Forms.ScrollableControl)

Disposing

(Inherited from System.Windows.Forms.Control)

Dock

(Inherited from System.Windows.Forms.Control)

Document

Gets or sets the document shown by the preview.

Enabled

(Inherited from System.Windows.Forms.Control)

ExportOptions

Gets options controlling the behavior of export


modules.

Focused

(Inherited from System.Windows.Forms.Control)

Font

(Inherited from System.Windows.Forms.Control)

Handle

(Inherited from System.Windows.Forms.Control)

HasChildren

(Inherited from System.Windows.Forms.Control)

Height

(Inherited from System.Windows.Forms.Control)

HorizontalScroll

(Inherited from
System.Windows.Forms.ScrollableControl)

ImageSet

Gets or sets a value indicating which set of predefined


images is used by the preview.

ImeMode

(Inherited from System.Windows.Forms.Control)

InvokeRequired

(Inherited from System.Windows.Forms.Control)

IsAccessible

(Inherited from System.Windows.Forms.Control)

IsDisposed

(Inherited from System.Windows.Forms.Control)

IsHandleCreated

(Inherited from System.Windows.Forms.Control)

IsMirrored

(Inherited from System.Windows.Forms.Control)

LayoutEngine

(Inherited from System.Windows.Forms.Control)

Left

(Inherited from System.Windows.Forms.Control)

LeftToolStripPanel

For internal use.

LeftToolStripPanelVisible

For internal use.

Location

(Inherited from System.Windows.Forms.Control)

Margin

(Inherited from System.Windows.Forms.Control)

MaximumSize

(Inherited from System.Windows.Forms.Control)

MinimumSize

(Inherited from System.Windows.Forms.Control)

Name

(Inherited from System.Windows.Forms.Control)

NavigationPanelVisible

Gets or sets a value indicating whether the navigation


panel should be visible in the preview.

OutlineViewCaption

Gets or sets the outline view caption.

Padding

(Inherited from System.Windows.Forms.Control)

Parent

(Inherited from System.Windows.Forms.Control)

ParentForm

(Inherited from
System.Windows.Forms.ContainerControl)

PreferredSize

(Inherited from System.Windows.Forms.Control)

PreviewNavigationPanel

Gets the preview navigation panel.

PreviewOutlineView

Gets the preview outline view.

PreviewPane

Gets the preview pane.

PreviewProgressBar

Gets the preview progress bar.

PreviewStatusBar

Gets the preview status bar.

PreviewStatusText

Gets the preview status.

PreviewTextSearchPanel

Gets the preview text search panel.

PreviewThumbnailView

Gets the preview thumbnails view.

ProductName

(Inherited from System.Windows.Forms.Control)

ProductVersion

(Inherited from System.Windows.Forms.Control)

RecreatingHandle

(Inherited from System.Windows.Forms.Control)

Region

(Inherited from System.Windows.Forms.Control)

Right

(Inherited from System.Windows.Forms.Control)

RightToLeft

(Inherited from System.Windows.Forms.Control)

RightToolStripPanel

For internal use.

RightToolStripPanelVisible

For internal use.

Site

(Inherited from System.Windows.Forms.Control)

Size

(Inherited from System.Windows.Forms.Control)

SsrsPaginated

Gets or sets whether an SSRS report should appear in


paginated mode (for printing) or in RPL mode
(interactive).

StatusBarVisible

Gets or sets a value indicating whether the status bar


should be visible in the preview.

TabIndex

(Inherited from System.Windows.Forms.Control)

TabStop

(Inherited from System.Windows.Forms.Control)

Tag

(Inherited from System.Windows.Forms.Control)

Text

(Inherited from System.Windows.Forms.Control)

TextSearchPanelVisible

Gets or sets a value indicating whether the text search


panel should be visible in the preview.

TextSearchUIStyle

Gets or sets the type of UI used for text search.

ThumbnailViewCaption

Gets or sets the thumbnail view caption.

ToolBars

Gets the preview control toolbars.

Top

(Inherited from System.Windows.Forms.Control)

TopLevelControl

(Inherited from System.Windows.Forms.Control)

TopToolStripPanel

For internal use.

TopToolStripPanelVisible

For internal use.

UseWaitCursor

(Inherited from System.Windows.Forms.Control)

VerticalScroll

(Inherited from
System.Windows.Forms.ScrollableControl)

Visible

(Inherited from System.Windows.Forms.Control)

Width

(Inherited from System.Windows.Forms.Control)

Top

Public Methods
Name

Description

BeginInvoke

Overloaded. (Inherited from System.Windows.Forms.Control)

BringToFront

(Inherited from System.Windows.Forms.Control)

Contains

(Inherited from System.Windows.Forms.Control)

CreateControl

(Inherited from System.Windows.Forms.Control)

CreateGraphics

(Inherited from System.Windows.Forms.Control)

CreateObjRef

(Inherited from System.MarshalByRefObject)

Dispose

(Inherited from System.ComponentModel.Component)

DoDragDrop

(Inherited from System.Windows.Forms.Control)

DrawToBitmap

(Inherited from System.Windows.Forms.Control)

EndInvoke

(Inherited from System.Windows.Forms.Control)

FindForm

(Inherited from System.Windows.Forms.Control)

Focus

(Inherited from System.Windows.Forms.Control)

GetChildAtPoint

Overloaded. (Inherited from System.Windows.Forms.Control)

GetContainerControl

(Inherited from System.Windows.Forms.Control)

GetLifetimeService

(Inherited from System.MarshalByRefObject)

GetNextControl

(Inherited from System.Windows.Forms.Control)

GetPreferredSize

(Inherited from System.Windows.Forms.Control)

Hide

(Inherited from System.Windows.Forms.Control)

InitializeLifetimeService

(Inherited from System.MarshalByRefObject)

Invalidate

Overloaded. (Inherited from System.Windows.Forms.Control)

Invoke

Overloaded. (Inherited from System.Windows.Forms.Control)

PerformAutoScale

(Inherited from System.Windows.Forms.ContainerControl)

PerformLayout

Overloaded. (Inherited from System.Windows.Forms.Control)

PointToClient

(Inherited from System.Windows.Forms.Control)

PointToScreen

(Inherited from System.Windows.Forms.Control)

PreProcessControlMessage (Inherited from System.Windows.Forms.Control)


PreProcessMessage

(Inherited from System.Windows.Forms.Control)

RectangleToClient

(Inherited from System.Windows.Forms.Control)

RectangleToScreen

(Inherited from System.Windows.Forms.Control)

Refresh

(Inherited from System.Windows.Forms.Control)

ResetText

(Inherited from System.Windows.Forms.Control)

ResumeLayout

Overloaded. (Inherited from System.Windows.Forms.Control)

Scale

(Inherited from System.Windows.Forms.Control)

ScrollControlIntoView

(Inherited from System.Windows.Forms.ScrollableControl)

Select

(Inherited from System.Windows.Forms.Control)

SelectNextControl

(Inherited from System.Windows.Forms.Control)

SendToBack

(Inherited from System.Windows.Forms.Control)

SetAutoScrollMargin

(Inherited from System.Windows.Forms.ScrollableControl)

SetBounds

Overloaded. (Inherited from System.Windows.Forms.Control)

Show

(Inherited from System.Windows.Forms.Control)

SuspendLayout

(Inherited from System.Windows.Forms.Control)

ToString

(Inherited from System.ComponentModel.Component)

Update

(Inherited from System.Windows.Forms.Control)

Validate

Overloaded. (Inherited from


System.Windows.Forms.ContainerControl)

Top

Public Events
Name

Description

BindingContextChanged (Inherited from System.Windows.Forms.Control)


ChangeUICues

(Inherited from System.Windows.Forms.Control)

Click

(Inherited from System.Windows.Forms.Control)

ClientSizeChanged

(Inherited from System.Windows.Forms.Control)

ContextMenuChanged

(Inherited from System.Windows.Forms.Control)

ControlAdded

(Inherited from System.Windows.Forms.Control)

ControlRemoved

(Inherited from System.Windows.Forms.Control)

Disposed

(Inherited from System.ComponentModel.Component)

DockChanged

(Inherited from System.Windows.Forms.Control)

DoubleClick

(Inherited from System.Windows.Forms.Control)

DragDrop

(Inherited from System.Windows.Forms.Control)

DragEnter

(Inherited from System.Windows.Forms.Control)

DragLeave

(Inherited from System.Windows.Forms.Control)

DragOver

(Inherited from System.Windows.Forms.Control)

EnabledChanged

(Inherited from System.Windows.Forms.Control)

Enter

(Inherited from System.Windows.Forms.Control)

FontChanged

(Inherited from System.Windows.Forms.Control)

GiveFeedback

(Inherited from System.Windows.Forms.Control)

GotFocus

(Inherited from System.Windows.Forms.Control)

HandleCreated

(Inherited from System.Windows.Forms.Control)

HandleDestroyed

(Inherited from System.Windows.Forms.Control)

HelpRequested

(Inherited from System.Windows.Forms.Control)

ImeModeChanged

(Inherited from System.Windows.Forms.Control)

Invalidated

(Inherited from System.Windows.Forms.Control)

KeyDown

(Inherited from System.Windows.Forms.Control)

KeyPress

(Inherited from System.Windows.Forms.Control)

KeyUp

(Inherited from System.Windows.Forms.Control)

Layout

(Inherited from System.Windows.Forms.Control)

Leave

(Inherited from System.Windows.Forms.Control)

LocationChanged

(Inherited from System.Windows.Forms.Control)

LostFocus

(Inherited from System.Windows.Forms.Control)

MarginChanged

(Inherited from System.Windows.Forms.Control)

MouseCaptureChanged (Inherited from System.Windows.Forms.Control)


MouseClick

(Inherited from System.Windows.Forms.Control)

MouseDoubleClick

(Inherited from System.Windows.Forms.Control)

MouseDown

(Inherited from System.Windows.Forms.Control)

MouseEnter

(Inherited from System.Windows.Forms.Control)

MouseHover

(Inherited from System.Windows.Forms.Control)

MouseLeave

(Inherited from System.Windows.Forms.Control)

MouseMove

(Inherited from System.Windows.Forms.Control)

MouseUp

(Inherited from System.Windows.Forms.Control)

MouseWheel

(Inherited from System.Windows.Forms.Control)

Move

(Inherited from System.Windows.Forms.Control)

PaddingChanged

(Inherited from System.Windows.Forms.Control)

Paint

(Inherited from System.Windows.Forms.Control)

ParentChanged

(Inherited from System.Windows.Forms.Control)

PreviewKeyDown

(Inherited from System.Windows.Forms.Control)

QueryAccessibilityHelp

(Inherited from System.Windows.Forms.Control)

QueryContinueDrag

(Inherited from System.Windows.Forms.Control)

RegionChanged

(Inherited from System.Windows.Forms.Control)

Resize

(Inherited from System.Windows.Forms.Control)

RightToLeftChanged

(Inherited from System.Windows.Forms.Control)

Scroll

(Inherited from System.Windows.Forms.ScrollableControl)

SizeChanged

(Inherited from System.Windows.Forms.Control)

StyleChanged

(Inherited from System.Windows.Forms.Control)

SystemColorsChanged

(Inherited from System.Windows.Forms.Control)

TabIndexChanged

(Inherited from System.Windows.Forms.Control)

TabStopChanged

(Inherited from System.Windows.Forms.Control)

TextChanged

(Inherited from System.Windows.Forms.Control)

Validated

(Inherited from System.Windows.Forms.Control)

Validating

(Inherited from System.Windows.Forms.Control)

VisibleChanged

(Inherited from System.Windows.Forms.Control)

Top

See Also
Reference

C1PrintPreviewControl Class
C1.Win.C1Preview Namespace

TempFileName Property
Gets or sets the name of the temporary file to use when adding entries to the zip file.

Syntax
Visual Basic (Declaration)
Public Property TempFileName As String
C#
public string TempFileName {get; set;}

Remarks
C1ZipFile creates temporary streams while adding entries to a zip file. These temporary streams
can be memory-based or disk-based, depending on the size of the entry and on the setting of
the MemoryThreshold property.
If a temporary file is used, C1ZipFile you can control its location by setting the TempFileName
property. If you don't select a path for the temporary file, C1ZipFile will create one automatically
using the System.IO.Path.GetTempFileName method.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

UseUtf8Encoding Property
Determines whether file names and comments should be stored in UTF8 format.

Syntax
Visual Basic (Declaration)
Public Property UseUtf8Encoding As Boolean

C#
public bool UseUtf8Encoding {get; set;}

Remarks
The Zip specification does not specify what character encoding to be used for the embedded
file names and comments. The original IBM PC character encoding set, commonly referred to as
IBM Code Page 437, is supposed to be the only encoding supported. Because of this, some zip
utilities will not allow storing file names or comments with Unicode characters. Others do allow
it, but those file names and comments may not be read correctly by other utilities.
Setting the UseUtf8Encoding to true causes C1Zip to store and retrieve file names and
comments using the Utf8 encoding, which allows Unicode characters. The caveat is that
Unicode file names may not be read correctly by other zip utilities.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZipFile Class
C1ZipFile Members

Events
%%scrap%%
" -->
For a list of all members of this type, see C1ZipFile members.

Public Events
Name

Description

Progress

Fired while data is being read from or written into a zip file.

Top

See Also
Reference

C1ZipFile Class
C1.C1Zip Namespace

Progress Event
For internal use.

Syntax
Visual Basic (Declaration)
Public Shadows Property BottomToolStripPanelVisible As System.Boolean
C#
public new System.bool BottomToolStripPanelVisible {get; set;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1PrintPreviewControl Class
C1PrintPreviewControl Members

C1ZStreamReader
Example

Decompresses data from .NET streams.

Object Model

Syntax
Visual Basic (Declaration)
Public Class C1ZStreamReader
Inherits System.IO.Stream
C#

public class C1ZStreamReader : System.IO.Stream

Remarks
To decompress data from a compressed stream, create a C1ZStreamReader object passing the
compressed stream to the C1ZStreamReader constructor.
Then read the data from the C1ZStreamReader using the Read method, or create a
System.IO.StreamReader on the C1ZStreamReader. The second option is indicated when you
want to read formatted data.

Example
The code below decompresses a string that was stored into a memory stream object:

C#

public string ExpandString(byte[] buffer)


{
// turn buffer into a memory stream
var ms = new MemoryStream(buffer);
// attach decompressor stream to memory stream
var sr = new C1ZStreamReader(ms);
// read uncompressed data
var reader = new StreamReader(sr);
return reader.ReadToEnd();
}

Inheritance Hierarchy
System.Object
System.MarshalByRefObject
System.IO.Stream
C1.C1Zip.C1ZStreamReader

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Members
C1.C1Zip Namespace

Overview
Example

Decompresses data from .NET streams.

Object Model

Syntax
Visual Basic (Declaration)
Public Class C1ZStreamReader
Inherits System.IO.Stream
C#
public class C1ZStreamReader : System.IO.Stream

Remarks
To decompress data from a compressed stream, create a C1ZStreamReader object passing the
compressed stream to the C1ZStreamReader constructor.
Then read the data from the C1ZStreamReader using the Read method, or create a
System.IO.StreamReader on the C1ZStreamReader. The second option is indicated when you
want to read formatted data.

Example
The code below decompresses a string that was stored into a memory stream object:

C#

public string ExpandString(byte[] buffer)


{
// turn buffer into a memory stream
var ms = new MemoryStream(buffer);
// attach decompressor stream to memory stream
var sr = new C1ZStreamReader(ms);
// read uncompressed data
var reader = new StreamReader(sr);
return reader.ReadToEnd();
}

Inheritance Hierarchy

System.Object
System.MarshalByRefObject
System.IO.Stream
C1.C1Zip.C1ZStreamReader

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Members
C1.C1Zip Namespace

Members
Properties Methods

The following tables list the members exposed by C1ZStreamReader.

Public Constructors
Name

Description

C1ZStreamReader Constructor Overloaded.


Top

Public Properties
Name

Description

BaseStream

Gets the underlying stream that contains the compressed data.

CanRead

Overridden. Always returns True.

CanSeek

Overridden. Always returns False.

CanTimeout

(Inherited from System.IO.Stream)

CanWrite

Overridden. Always returns False.

Length

Overridden. Gets the length of the compressed stream if it is


known (or -1 if the length of the compressed stream is
unknown).

OwnsBaseStream

Gets or sets whether calling the Close method will also close the
underlying stream (see BaseStream).

Position

Overridden. Gets the position within the stream (read-only).

ReadTimeout

(Inherited from System.IO.Stream)

SizeCompressed

Gets the number of bytes in the stream (compressed bytes).

SizeCompressedLong

Gets the number of bytes in the stream (compressed bytes).

SizeUncompressed

Gets the number of bytes that were compressed into the stream
(uncompressed bytes).

SizeUncompressedLong Gets the number of bytes that were compressed into the stream
(uncompressed bytes).
WriteTimeout

(Inherited from System.IO.Stream)

ZStream

Gets the ZStream instance wrapped by this C1ZStreamWriter.

Top

Public Methods
Name

Description

BeginRead

(Inherited from System.IO.Stream)

BeginWrite

(Inherited from System.IO.Stream)

Close

Overridden.
Closes the current stream compressor and flushed any pending

data into the base stream.


If the OwnsBaseStream property is set to True (the default value),
then this method also closes the base stream and releases any
resources (such as sockets and file handles) associated with it.

CopyTo

Overloaded. (Inherited from System.IO.Stream)

CopyToAsync

Overloaded. (Inherited from System.IO.Stream)

CreateObjRef

(Inherited from System.MarshalByRefObject)

Dispose

(Inherited from System.IO.Stream)

EndRead

(Inherited from System.IO.Stream)

EndWrite

(Inherited from System.IO.Stream)

Flush

Overridden. Clears all buffers for this stream and causes any
buffered data to be written to the underlying stream.

FlushAsync

Overloaded. (Inherited from System.IO.Stream)

GetLifetimeService

(Inherited from System.MarshalByRefObject)

InitializeLifetimeService (Inherited from System.MarshalByRefObject)


Read

Overridden. Reads a sequence of bytes from the underlying


compressed stream, decompressing them into a buffer, then
advances the position within the stream by the number of bytes
read.

ReadAsync

Overloaded. (Inherited from System.IO.Stream)

ReadByte

Overridden. Reads a byte from the stream and advances the


position within the stream by one byte, or returns -1 if at the end

of the stream.
Seek

Overridden. Not supported.

SetLength

Overridden. Sets the number of compressed bytes to read from the


underlying stream.

Write

Overridden. This method is overridden and is not supported by the


C1ZStreamReader class.

WriteAsync

Overloaded. (Inherited from System.IO.Stream)

WriteByte

(Inherited from System.IO.Stream)

Top

See Also
Reference
C1ZStreamReader Class
C1.C1Zip Namespace

C1ZStreamReader Constructor

Overload List
Overload

Description

C1ZStreamReader Constructor(Stream)

Initializes a new instance of the


C1ZStreamReader class.

C1ZStreamReader Constructor(Stream,Boolean,Int32)

Initializes a new instance of the


C1ZStreamReader class.

C1ZStreamReader Constructor(Stream,Boolean)

Initializes a new instance of the


C1ZStreamReader class.

C1ZStreamReader Constructor(Stream,Boolean,Boolean)

Initializes a new instance of the


C1ZStreamReader class.

C1ZStreamReader Constructor(Stream,Boolean,Int32,Int32) Initializes a new instance of the


C1ZStreamReader class.
C1ZStreamReader Constructor(Stream,Boolean,Int64,Int32) Initializes a new instance of the
C1ZStreamReader class.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

C1ZStreamReader Constructor(Stream)
Input stream that contains the compressed data.
Initializes a new instance of the C1ZStreamReader class.

Syntax
Visual Basic (Declaration)
Public Function New( _
ByVal baseStream As Stream _
)
C#
public C1ZStreamReader(
Stream baseStream
)

Parameters
baseStream
Input stream that contains the compressed data.

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members
Overload List

C1ZStreamReader Constructor(Stream,Boolean,Int32)
Input stream that contains the compressed data.
Specifies whether the compressed stream was created in zip format.
Specifies the number of compressed bytes to read from the stream.
Initializes a new instance of the C1ZStreamReader class.

Syntax
Visual Basic (Declaration)
Public Function New( _
ByVal baseStream As Stream, _
ByVal zip As Boolean, _
ByVal sizeCompressed As Integer _
)
C#
public C1ZStreamReader(
Stream baseStream,
bool zip,
int sizeCompressed
)

Parameters
baseStream
Input stream that contains the compressed data.
zip
Specifies whether the compressed stream was created in zip format.

sizeCompressed
Specifies the number of compressed bytes to read from the stream.

Remarks
The sizeCompressed parameter is needed only when a single stream contains
several compressed streams (in zip files for example). If this parameter is not
specified, it is assumed that the stream contains a single stream of compressed
data.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2
(Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members
Overload List

C1ZStreamReader Constructor(Stream,Boolean)
Input stream that contains the compressed data.
Specifies whether the compressed stream was created in zip format.
Initializes a new instance of the C1ZStreamReader class.

Syntax
Visual Basic (Declaration)
Public Function New( _
ByVal baseStream As Stream, _
ByVal zip As Boolean _
)
C#
public C1ZStreamReader(
Stream baseStream,
bool zip
)

Parameters
baseStream
Input stream that contains the compressed data.
zip
Specifies whether the compressed stream was created in zip format.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members
Overload List

C1ZStreamReader Constructor(Stream,Boolean,Boolean)
Input stream that contains the compressed data.
Specifies whether the compressed stream contains header information (should be False for
streams in zip files).
Specifies whether the compressed stream contains a CRC32 checksum (should be True for
streams in zip files).
Initializes a new instance of the C1ZStreamReader class.

Syntax
Visual Basic (Declaration)
Public Function New( _
ByVal baseStream As Stream, _
ByVal header As Boolean, _
ByVal crc32 As Boolean _
)
C#
public C1ZStreamReader(

Stream baseStream,
bool header,
bool crc32
)

Parameters
baseStream
Input stream that contains the compressed data.
header
Specifies whether the compressed stream contains header information (should be False
for streams in zip files).
crc32
Specifies whether the compressed stream contains a CRC32 checksum (should be True
for streams in zip files).

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2
(Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members
Overload List

C1ZStreamReader Constructor(Stream,Boolean,Int32,Int32)
Input stream that contains the compressed data.
Specifies whether the compressed stream was created in zip format.
Specifies the number of compressed bytes to read from the stream.
Specifies the method that was used to compress the stream.
Initializes a new instance of the C1ZStreamReader class.

Syntax
Visual Basic (Declaration)

Public Function New( _


ByVal baseStream As Stream, _
ByVal zip As Boolean, _
ByVal sizeCompressed As Integer, _
ByVal method As Integer _
)
C#
public C1ZStreamReader(
Stream baseStream,
bool zip,
int sizeCompressed,
int method
)

Parameters
baseStream
Input stream that contains the compressed data.
zip
Specifies whether the compressed stream was created in zip format.
sizeCompressed
Specifies the number of compressed bytes to read from the stream.
method
Specifies the method that was used to compress the stream.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP
SP3, Windows Server 2008 (Server Core not supported), Windows Server
2008 R2 (Server Core supported with SP1 or later), Windows Server 2003
SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members
Overload List

C1ZStreamReader Constructor(Stream,Boolean,Int64,Int32)
Input stream that contains the compressed data.
Specifies whether the compressed stream was created in zip format.
Specifies the number of compressed bytes to read from the stream.
Specifies the method that was used to compress the stream.
Initializes a new instance of the C1ZStreamReader class.

Syntax
Visual Basic (Declaration)
Public Function New( _
ByVal baseStream As Stream, _
ByVal zip As Boolean, _
ByVal sizeCompressed As Long, _
ByVal method As Integer _
)
C#
public C1ZStreamReader(
Stream baseStream,
bool zip,
long sizeCompressed,
int method
)

Parameters
baseStream
Input stream that contains the compressed data.
zip
Specifies whether the compressed stream was created in zip format.
sizeCompressed
Specifies the number of compressed bytes to read from the stream.
method
Specifies the method that was used to compress the stream.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP
SP3, Windows Server 2008 (Server Core not supported), Windows Server
2008 R2 (Server Core supported with SP1 or later), Windows Server 2003
SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members
Overload List

Methods
>
Name

Description

BeginRead

(Inherited from System.IO.Stream)

BeginWrite

(Inherited from System.IO.Stream)


Overridden.
Closes the current stream compressor and flushed any pending data
into the base stream.

Close

If the OwnsBaseStream property is set to True (the default value),


then this method also closes the base stream and releases any
resources (such as sockets and file handles) associated with it.

CopyTo

Overloaded. (Inherited from System.IO.Stream)

CopyToAsync

Overloaded. (Inherited from System.IO.Stream)

CreateObjRef

(Inherited from System.MarshalByRefObject)

Dispose

(Inherited from System.IO.Stream)

EndRead

(Inherited from System.IO.Stream)

EndWrite

(Inherited from System.IO.Stream)

Flush

Overridden. Clears all buffers for this stream and causes any
buffered data to be written to the underlying stream.

FlushAsync

Overloaded. (Inherited from System.IO.Stream)

GetLifetimeService

(Inherited from System.MarshalByRefObject)

InitializeLifetimeService (Inherited from System.MarshalByRefObject)


Overridden. Reads a sequence of bytes from the underlying
Read

compressed stream, decompressing them into a buffer, then


advances the position within the stream by the number of bytes
read.

ReadAsync

Overloaded. (Inherited from System.IO.Stream)


Overridden. Reads a byte from the stream and advances the position

ReadByte

within the stream by one byte, or returns -1 if at the end of the


stream.

Seek
SetLength

Write

Overridden. Not supported.


Overridden. Sets the number of compressed bytes to read from the
underlying stream.
Overridden. This method is overridden and is not supported by the
C1ZStreamReader class.

WriteAsync

Overloaded. (Inherited from System.IO.Stream)

WriteByte

(Inherited from System.IO.Stream)

Top

See Also
Reference
C1ZStreamReader Class
C1.C1Zip Namespace

Close Method
Closes the current stream compressor and flushed any pending data into the base stream.
If the OwnsBaseStream property is set to True (the default value), then this method also closes
the base stream and releases any resources (such as sockets and file handles) associated with it.

Syntax

Visual Basic (Declaration)


Public Overrides Sub Close()
C#
public override void Close()

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

Flush Method
Clears all buffers for this stream and causes any buffered data to be written to the underlying
stream.

Syntax
Visual Basic (Declaration)
Public Overrides Sub Flush()
C#
public override void Flush()

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

Read Method
An array of bytes. When this method returns, buf contains the specified byte array with the
values between offsetand (offset + count) replaced by the uncompressed data read from the
stream.
The zero-based byte offset in buf at which to begin storing the data read from the current
stream.
The maximum number of (decompressed) bytes to be read from the current stream.
Reads a sequence of bytes from the underlying compressed stream, decompressing them into a
buffer, then advances the position within the stream by the number of bytes read.

Syntax
Visual Basic (Declaration)
Public Overrides Function Read( _
ByVal buf() As Byte, _
ByVal offset As Integer, _
ByVal count As Integer _
) As Integer
C#
public override int Read(
byte[] buf,
int offset,
int count
)

Parameters
buf
An array of bytes. When this method returns, buf contains the specified byte array with
the values between offsetand (offset + count) replaced by the uncompressed data read
from the stream.
offset
The zero-based byte offset in buf at which to begin storing the data read from the
current stream.
count
The maximum number of (decompressed) bytes to be read from the current stream.

Return Value

The total number of bytes read into the buffer. This may be less than the
number of bytes requested if that many bytes are not currently available, or
zero (0) if the end of the stream has been reached.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2
(Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

ReadByte Method
Reads a byte from the stream and advances the position within the stream by one byte, or
returns -1 if at the end of the stream.

Syntax
Visual Basic (Declaration)
Public Overrides Function ReadByte() As Integer
C#
public override int ReadByte()

Return Value
The unsigned byte cast to an System.Int32, or -1 if at the end of the stream.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

Seek Method
Not supported.

Syntax
Visual Basic (Declaration)
Public Overrides Function Seek( _
ByVal offset As Long, _
ByVal origin As SeekOrigin _
) As Long
C#
public override long Seek(
long offset,
SeekOrigin origin
)

Parameters
offset
origin

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

SetLength Method
Sets the number of compressed bytes to read from the underlying stream.

Syntax
Visual Basic (Declaration)
Public Overrides Sub SetLength( _

ByVal value As Long _


)
C#
public override void SetLength(
long value
)

Parameters
value

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

Write Method
This method is overridden and is not supported by the C1ZStreamReader class.

Syntax
Visual Basic (Declaration)
Public Overrides Sub Write( _
ByVal buf() As Byte, _
ByVal offset As Integer, _
ByVal count As Integer _
)
C#
public override void Write(
byte[] buf,
int offset,
int count
)

Parameters
buf
offset
count

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2
(Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

Properties
%%scrap%%
" -->
For a list of all members of this type, see C1ZStreamReader members.

Public Properties
Name

Description

BaseStream

Gets the underlying stream that contains the compressed data.

CanRead

Overridden. Always returns True.

CanSeek

Overridden. Always returns False.

CanTimeout

(Inherited from System.IO.Stream)

CanWrite

Overridden. Always returns False.

Length

Overridden. Gets the length of the compressed stream if it is


known (or -1 if the length of the compressed stream is

unknown).
OwnsBaseStream

Gets or sets whether calling the Close method will also close the
underlying stream (see BaseStream).

Position

Overridden. Gets the position within the stream (read-only).

ReadTimeout

(Inherited from System.IO.Stream)

SizeCompressed

Gets the number of bytes in the stream (compressed bytes).

SizeCompressedLong

Gets the number of bytes in the stream (compressed bytes).

SizeUncompressed

Gets the number of bytes that were compressed into the stream
(uncompressed bytes).

SizeUncompressedLong Gets the number of bytes that were compressed into the stream
(uncompressed bytes).
WriteTimeout

(Inherited from System.IO.Stream)

ZStream

Gets the ZStream instance wrapped by this C1ZStreamWriter.

Top

See Also
Reference
C1ZStreamReader Class
C1.C1Zip Namespace

BaseStream Property
Gets the underlying stream that contains the compressed data.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property BaseStream As Stream

C#
public Stream BaseStream {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

CanRead Property
Always returns True.

Syntax
Visual Basic (Declaration)
Public Overrides ReadOnly Property CanRead As Boolean
C#
public override bool CanRead {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

CanSeek Property
Always returns False.

Syntax

Visual Basic (Declaration)


Public Overrides ReadOnly Property CanSeek As Boolean
C#
public override bool CanSeek {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

CanWrite Property
Always returns False.

Syntax
Visual Basic (Declaration)
Public Overrides ReadOnly Property CanWrite As Boolean
C#
public override bool CanWrite {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

Length Property
Gets the length of the compressed stream if it is known (or -1 if the length of the compressed
stream is unknown).

Syntax
Visual Basic (Declaration)
Public Overrides ReadOnly Property Length As Long
C#
public override long Length {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

OwnsBaseStream Property
Gets or sets whether calling the Close method will also close the underlying stream (see
BaseStream).

Syntax
Visual Basic (Declaration)
Public Property OwnsBaseStream As Boolean
C#
public bool OwnsBaseStream {get; set;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

Position Property
Gets the position within the stream (read-only).

Syntax
Visual Basic (Declaration)
Public Overrides Property Position As Long
C#
public override long Position {get; set;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

SizeCompressed Property
Gets the number of bytes in the stream (compressed bytes).

Syntax
Visual Basic (Declaration)
Public ReadOnly Property SizeCompressed As Integer
C#
public int SizeCompressed {get;}

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

SizeCompressedLong Property
Gets the number of bytes in the stream (compressed bytes).

Syntax
Visual Basic (Declaration)
Public ReadOnly Property SizeCompressedLong As Long
C#
public long SizeCompressedLong {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

SizeUncompressed Property
Gets the number of bytes that were compressed into the stream (uncompressed bytes).

Syntax
Visual Basic (Declaration)
Public ReadOnly Property SizeUncompressed As Integer

C#
public int SizeUncompressed {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

SizeUncompressedLong Property
Gets the number of bytes that were compressed into the stream (uncompressed bytes).

Syntax
Visual Basic (Declaration)
Public ReadOnly Property SizeUncompressedLong As Long
C#
public long SizeUncompressedLong {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

ZStream Property
Gets the ZStream instance wrapped by this C1ZStreamWriter.

Syntax

Visual Basic (Declaration)


Public ReadOnly Property ZStream As ZStream
C#
public ZStream ZStream {get;}

Remarks
This property is useful only in advanced applications that need to customize the low-level
behavior of the compressor. It is not needed in common applications.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamReader Class
C1ZStreamReader Members

C1ZStreamWriter
Example

Compresses data into .NET Streams.

Object Model

Syntax
Visual Basic (Declaration)
Public Class C1ZStreamWriter
Inherits System.IO.Stream
C#
public class C1ZStreamWriter : System.IO.Stream

Remarks

To compress data into a stream, create a C1ZStreamWriter object passing the stream to the
C1ZStreamWriter constructor.
Then write the data into the C1ZStreamWriter using the Write method, or create a
System.IO.StreamWriter on the C1ZStreamWriter. The second option is indicated when you
want to write formatted data.
When you are done writing the data, call the Close method to flush the data and close the
underlying stream.

Example
The code below compresses a string into a memory stream:

C#

public byte[] CompressString(string str)


{
// open memory stream
var ms = new MemoryStream();
// attach compressor stream to memory stream
var sw = new C1ZStreamWriter(ms);
// write data into compressor stream
var writer = new StreamWriter(sw);
writer.Write(str);
// flush any pending data
writer.Flush();
// return the memory buffer
return ms.ToArray();
}

Inheritance Hierarchy
System.Object
System.MarshalByRefObject
System.IO.Stream
C1.C1Zip.C1ZStreamWriter

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference

C1ZStreamWriter Members
C1.C1Zip Namespace

Overview
Example

Compresses data into .NET Streams.

Object Model

Syntax
Visual Basic (Declaration)
Public Class C1ZStreamWriter
Inherits System.IO.Stream
C#
public class C1ZStreamWriter : System.IO.Stream

Remarks
To compress data into a stream, create a C1ZStreamWriter object passing the stream to the
C1ZStreamWriter constructor.
Then write the data into the C1ZStreamWriter using the Write method, or create a
System.IO.StreamWriter on the C1ZStreamWriter. The second option is indicated when you
want to write formatted data.
When you are done writing the data, call the Close method to flush the data and close the
underlying stream.

Example
The code below compresses a string into a memory stream:

C#

public byte[] CompressString(string str)


{
// open memory stream
var ms = new MemoryStream();
// attach compressor stream to memory stream
var sw = new C1ZStreamWriter(ms);

// write data into compressor stream


var writer = new StreamWriter(sw);
writer.Write(str);
// flush any pending data
writer.Flush();
// return the memory buffer
return ms.ToArray();
}

Inheritance Hierarchy
System.Object
System.MarshalByRefObject
System.IO.Stream
C1.C1Zip.C1ZStreamWriter

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Members
C1.C1Zip Namespace

Members
Properties Methods

The following tables list the members exposed by C1ZStreamWriter.

Public Constructors
Name

Description

C1ZStreamWriter Constructor Overloaded.


Top

Public Properties
Name

Description

BaseStream

Gets the underlying stream that receives the compressed data.

CanRead

Overridden. Always returns False.

CanSeek

Overridden. Always returns False.

CanTimeout

(Inherited from System.IO.Stream)

CanWrite

Overridden. Always returns True.

Checksum

Gets the checksum value used to check the integrity of the


stream.

Length

Overridden. Returns the length of the underlying stream, in


bytes.

OwnsBaseStream

Gets or sets whether calling the Close method will also close the
underlying stream (see BaseStream).

Position

Overridden. Gets the position within the stream (read-only).

ReadTimeout

(Inherited from System.IO.Stream)

SizeCompressed

Gets the number of bytes in the stream (compressed bytes).

SizeCompressedLong

Gets the number of bytes in the stream (compressed bytes).

SizeUncompressed

Gets the number of bytes that were compressed into the stream
(uncompressed bytes).

SizeUncompressedLong Gets the number of bytes that were compressed into the stream
(uncompressed bytes).

Top

WriteTimeout

(Inherited from System.IO.Stream)

ZStream

Gets the ZStream instance wrapped by this C1ZStreamWriter.

Public Methods
Name

Description

BeginRead

(Inherited from System.IO.Stream)

BeginWrite

(Inherited from System.IO.Stream)

Close

Overridden.
Closes the current stream compressor and flushed any pending
data into the base stream.
If the OwnsBaseStream property is set to True (the default value),
then this method also closes the base stream and releases any
resources (such as sockets and file handles) associated with it.

CopyTo

Overloaded. (Inherited from System.IO.Stream)

CopyToAsync

Overloaded. (Inherited from System.IO.Stream)

CreateObjRef

(Inherited from System.MarshalByRefObject)

Dispose

(Inherited from System.IO.Stream)

EndRead

(Inherited from System.IO.Stream)

EndWrite

(Inherited from System.IO.Stream)

Flush

Overridden. Clears all buffers for this stream and causes any
buffered data to be written to the underlying stream.

FlushAsync

Overloaded. (Inherited from System.IO.Stream)

GetLifetimeService

(Inherited from System.MarshalByRefObject)

InitializeLifetimeService (Inherited from System.MarshalByRefObject)

Read

Overridden. Not supported.

ReadAsync

Overloaded. (Inherited from System.IO.Stream)

ReadByte

(Inherited from System.IO.Stream)

Seek

Overridden. Not supported.

SetLength

Overridden. Not supported.

Write

Overridden. Writes a sequence of bytes to the current stream and


advances the current position within this stream by the number of
bytes written.

WriteAsync

Overloaded. (Inherited from System.IO.Stream)

WriteByte

Overridden. Writes a byte to the current position in the stream and


advances the position within the stream by one byte.

Top

See Also
Reference
C1ZStreamWriter Class
C1.C1Zip Namespace

C1ZStreamWriter Constructor

Overload List
Overload

Description

C1ZStreamWriter Constructor(Stream)

Initializes a new
instance of the
C1ZStreamWrite
r class.

C1ZStreamWriter Constructor(Stream,Boolean)

Initializes a new
instance of the

C1ZStreamWrite
r class.
C1ZStreamWriter Constructor(Stream,Boolean,Boolean)

Initializes a new
instance of the
C1ZStreamWrite
r class.

C1ZStreamWriter Constructor(Stream,CompressionLevelEnum)

Initializes a new
instance of the
C1ZStreamWrite
r class.

C1ZStreamWriter Constructor(Stream,CompressionLevelEnum,Boolean)

Initializes a new
instance of the
C1ZStreamWrite
r class.

C1ZStreamWriter

Initializes a new

Constructor(Stream,CompressionLevelEnum,Boolean,Boolean)

instance of the
C1ZStreamWrite
r class.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

C1ZStreamWriter Constructor(Stream)
Output stream that will contain the compressed data.
Initializes a new instance of the C1ZStreamWriter class.

Syntax

Visual Basic (Declaration)


Public Function New( _
ByVal baseStream As Stream _
)
C#
public C1ZStreamWriter(
Stream baseStream
)

Parameters
baseStream
Output stream that will contain the compressed data.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members
Overload List

C1ZStreamWriter Constructor(Stream,Boolean)
Output stream that will contain the compressed data.
Specifies whether the compressed stream should be compatible with zip files.
Initializes a new instance of the C1ZStreamWriter class.

Syntax
Visual Basic (Declaration)
Public Function New( _
ByVal baseStream As Stream, _
ByVal zip As Boolean _
)

C#
public C1ZStreamWriter(
Stream baseStream,
bool zip
)

Parameters
baseStream
Output stream that will contain the compressed data.
zip
Specifies whether the compressed stream should be compatible with zip files.

Remarks
Streams in zip files are different from regular zlib streams in two aspects:
(1) zip streams do not contain any local header information (the information is stored
in the zip file headers instead) and
(2) zip streams use a CRC32 checksum instead of the adler32 checksum used by zlib
streams.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members
Overload List

C1ZStreamWriter Constructor(Stream,Boolean,Boolean)
>
Name
Open

Description
Gets the Open toolstrip button.

Owner

Gets the owner of this toolbar. (Inherited from


C1.Win.C1Preview.C1PrintPreviewControl.PreviewToolBar)

PageSetup

Gets the PageSetup toolstrip button.

Parameters

Gets the Parameters toolstrip button.

PreviewAction

Overridden. Gets C1PreviewActionFlags describing the content of this


toolbar.

PreviewControl

Gets the preview control containing this toolbar. (Inherited from


C1.Win.C1Preview.C1PrintPreviewControl.PreviewToolBar)

Print

Gets the Print toolstrip button.

PrintLayout

Gets the PrintLayout toolstrip button.

Reflow

Gets the Reflow toolstrip button.

Save

Gets the Save toolstrip button.

Stop

Gets the Stop toolstrip button.

ToolStrip

Visible

Gets the ToolStrip containing the buttons in this toolbar. (Inherited from
C1.Win.C1Preview.C1PrintPreviewControl.PreviewToolBar)
Gets or sets a value indicating whether this toolbar is visible. (Inherited
from C1.Win.C1Preview.C1PrintPreviewControl.PreviewToolBar)

Top

See Also
Reference
C1PrintPreviewControl.FileToolBar Class
C1.Win.C1Preview Namespace

C1ZStreamWriter Constructor(Stream,CompressionLevelEnum)
Output stream that will contain the compressed data.
Compression level to use when compressing data.
Initializes a new instance of the C1ZStreamWriter class.

Syntax

Visual Basic (Declaration)


Public Function New( _
ByVal baseStream As Stream, _
ByVal level As CompressionLevelEnum _
)
C#
public C1ZStreamWriter(
Stream baseStream,
CompressionLevelEnum level
)

Parameters
baseStream
Output stream that will contain the compressed data.
level
Compression level to use when compressing data.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members
Overload List

C1ZStreamWriter Constructor(Stream,CompressionLevelEnum,Boolean)
Output stream that will contain the compressed data.
Compression level to use when compressing data.
Specifies whether the compressed stream should be compatible with zip files.
Initializes a new instance of the C1ZStreamWriter class.

Syntax

Visual Basic (Declaration)


Public Function New( _
ByVal baseStream As Stream, _
ByVal level As CompressionLevelEnum, _
ByVal zip As Boolean _
)
C#
public C1ZStreamWriter(
Stream baseStream,
CompressionLevelEnum level,
bool zip
)

Parameters
baseStream
Output stream that will contain the compressed data.
level
Compression level to use when compressing data.
zip
Specifies whether the compressed stream should be compatible with zip files.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2
(Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members
Overload List

C1ZStreamWriter
Constructor(Stream,CompressionLevelEnum,Boolean,Boolean)
Output stream that will contain the compressed data.

Compression level to use when compressing data.


Include header information in compressed stream (should be False for streams in zip files).
Include CRC32 checksum in compressed stream (should be True for streams in zip files).
Initializes a new instance of the C1ZStreamWriter class.

Syntax
Visual Basic (Declaration)
Public Function New( _
ByVal baseStream As Stream, _
ByVal level As CompressionLevelEnum, _
ByVal header As Boolean, _
ByVal crc32 As Boolean _
)
C#
public C1ZStreamWriter(
Stream baseStream,
CompressionLevelEnum level,
bool header,
bool crc32
)

Parameters
baseStream
Output stream that will contain the compressed data.
level
Compression level to use when compressing data.
header
Include header information in compressed stream (should be False for streams in zip
files).
crc32
Include CRC32 checksum in compressed stream (should be True for streams in zip files).

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP


SP3, Windows Server 2008 (Server Core not supported), Windows Server
2008 R2 (Server Core supported with SP1 or later), Windows Server 2003
SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members
Overload List

Methods
>
Name

Description

BeginRead

(Inherited from System.IO.Stream)

BeginWrite

(Inherited from System.IO.Stream)


Overridden.
Closes the current stream compressor and flushed any pending data
into the base stream.

Close

If the OwnsBaseStream property is set to True (the default value),


then this method also closes the base stream and releases any
resources (such as sockets and file handles) associated with it.

CopyTo

Overloaded. (Inherited from System.IO.Stream)

CopyToAsync

Overloaded. (Inherited from System.IO.Stream)

CreateObjRef

(Inherited from System.MarshalByRefObject)

Dispose

(Inherited from System.IO.Stream)

EndRead

(Inherited from System.IO.Stream)

EndWrite

(Inherited from System.IO.Stream)

Flush

Overridden. Clears all buffers for this stream and causes any
buffered data to be written to the underlying stream.

FlushAsync

Overloaded. (Inherited from System.IO.Stream)

GetLifetimeService

(Inherited from System.MarshalByRefObject)

InitializeLifetimeService (Inherited from System.MarshalByRefObject)


Read

Overridden. Not supported.

ReadAsync

Overloaded. (Inherited from System.IO.Stream)

ReadByte

(Inherited from System.IO.Stream)

Seek

Overridden. Not supported.

SetLength

Overridden. Not supported.


Overridden. Writes a sequence of bytes to the current stream and

Write

advances the current position within this stream by the number of


bytes written.

WriteAsync
WriteByte

Overloaded. (Inherited from System.IO.Stream)


Overridden. Writes a byte to the current position in the stream and
advances the position within the stream by one byte.

Top

See Also
Reference
C1ZStreamWriter Class
C1.C1Zip Namespace

Close Method
Closes the current stream compressor and flushed any pending data into the base stream.
If the OwnsBaseStream property is set to True (the default value), then this method also closes
the base stream and releases any resources (such as sockets and file handles) associated with it.

Syntax
Visual Basic (Declaration)
Public Overrides Sub Close()
C#

public override void Close()

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

Flush Method
Clears all buffers for this stream and causes any buffered data to be written to the underlying
stream.

Syntax
Visual Basic (Declaration)
Public Overrides Sub Flush()
C#
public override void Flush()

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

Read Method
Not supported.

Syntax

Visual Basic (Declaration)


Public Overrides Function Read( _
ByVal buf() As Byte, _
ByVal offset As Integer, _
ByVal count As Integer _
) As Integer
C#
public override int Read(
byte[] buf,
int offset,
int count
)

Parameters
buf
offset
count

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2
(Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

Seek Method
Not supported.

Syntax
Visual Basic (Declaration)
Public Overrides Function Seek( _
ByVal offset As Long, _

ByVal origin As SeekOrigin _


) As Long
C#
public override long Seek(
long offset,
SeekOrigin origin
)

Parameters
offset
origin

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

SetLength Method
Not supported.

Syntax
Visual Basic (Declaration)
Public Overrides Sub SetLength( _
ByVal value As Long _
)
C#
public override void SetLength(
long value
)

Parameters

value

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

Write Method
An array of bytes. This method copies count bytes from buf to the current stream.
The zero-based byte offset in buf at which to begin copying bytes to the current stream.
The number of bytes to be written to the current stream.
Writes a sequence of bytes to the current stream and advances the current position within this
stream by the number of bytes written.

Syntax
Visual Basic (Declaration)
Public Overrides Sub Write( _
ByVal buf() As Byte, _
ByVal offset As Integer, _
ByVal count As Integer _
)
C#
public override void Write(
byte[] buf,
int offset,
int count
)

Parameters
buf
An array of bytes. This method copies count bytes from buf to the current stream.

offset
The zero-based byte offset in buf at which to begin copying bytes to the current
stream.
count
The number of bytes to be written to the current stream.

Remarks
The data is compressed as it is written into the stream. Writing count bytes into
the stream will usually advance the position by a number smaller than count.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2
(Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

WriteByte Method
Value to be written to the stream.
Writes a byte to the current position in the stream and advances the position within the stream
by one byte.

Syntax
Visual Basic (Declaration)
Public Overrides Sub WriteByte( _
ByVal value As Byte _
)
C#
public override void WriteByte(
byte value
)

Parameters

value
Value to be written to the stream.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

Properties
%%scrap%%
" -->
For a list of all members of this type, see C1ZStreamWriter members.

Public Properties
Name

Description

BaseStream

Gets the underlying stream that receives the compressed data.

CanRead

Overridden. Always returns False.

CanSeek

Overridden. Always returns False.

CanTimeout

(Inherited from System.IO.Stream)

CanWrite

Overridden. Always returns True.

Checksum

Gets the checksum value used to check the integrity of the


stream.

Length

Overridden. Returns the length of the underlying stream, in


bytes.

OwnsBaseStream

Gets or sets whether calling the Close method will also close the
underlying stream (see BaseStream).

Position

Overridden. Gets the position within the stream (read-only).

ReadTimeout

(Inherited from System.IO.Stream)

SizeCompressed

Gets the number of bytes in the stream (compressed bytes).

SizeCompressedLong

Gets the number of bytes in the stream (compressed bytes).

SizeUncompressed

Gets the number of bytes that were compressed into the stream
(uncompressed bytes).

SizeUncompressedLong Gets the number of bytes that were compressed into the stream
(uncompressed bytes).
WriteTimeout

(Inherited from System.IO.Stream)

ZStream

Gets the ZStream instance wrapped by this C1ZStreamWriter.

Top

See Also
Reference
C1ZStreamWriter Class
C1.C1Zip Namespace

BaseStream Property
Gets the underlying stream that receives the compressed data.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property BaseStream As Stream
C#
public Stream BaseStream {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

CanRead Property
Always returns False.

Syntax
Visual Basic (Declaration)
Public Overrides ReadOnly Property CanRead As Boolean
C#
public override bool CanRead {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

CanSeek Property
Always returns False.

Syntax
Visual Basic (Declaration)

Public Overrides ReadOnly Property CanSeek As Boolean


C#
public override bool CanSeek {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

CanWrite Property
Always returns True.

Syntax
Visual Basic (Declaration)
Public Overrides ReadOnly Property CanWrite As Boolean
C#
public override bool CanWrite {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

Checksum Property
Gets the checksum value used to check the integrity of the stream.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property Checksum As Integer
C#
public int Checksum {get;}

Remarks
The checksum used may be an Adler or crc32 value depending on how the C1ZStreamWriter
was created.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

Length Property
Returns the length of the underlying stream, in bytes.

Syntax
Visual Basic (Declaration)
Public Overrides ReadOnly Property Length As Long
C#
public override long Length {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

OwnsBaseStream Property
Gets or sets whether calling the Close method will also close the underlying stream (see
BaseStream).

Syntax
Visual Basic (Declaration)
Public Property OwnsBaseStream As Boolean
C#
public bool OwnsBaseStream {get; set;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

Position Property
Gets the position within the stream (read-only).

Syntax
Visual Basic (Declaration)
Public Overrides Property Position As Long
C#
public override long Position {get; set;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

SizeCompressed Property
Gets the number of bytes in the stream (compressed bytes).

Syntax
Visual Basic (Declaration)
Public ReadOnly Property SizeCompressed As Integer
C#
public int SizeCompressed {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

SizeCompressedLong Property
Gets the number of bytes in the stream (compressed bytes).

Syntax
Visual Basic (Declaration)

Public ReadOnly Property SizeCompressedLong As Long


C#
public long SizeCompressedLong {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

SizeUncompressed Property
Gets the number of bytes that were compressed into the stream (uncompressed bytes).

Syntax
Visual Basic (Declaration)
Public ReadOnly Property SizeUncompressed As Integer
C#
public int SizeUncompressed {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

SizeUncompressedLong Property
Gets the number of bytes that were compressed into the stream (uncompressed bytes).

Syntax
Visual Basic (Declaration)
Public ReadOnly Property SizeUncompressedLong As Long
C#
public long SizeUncompressedLong {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

ZStream Property
Gets the ZStream instance wrapped by this C1ZStreamWriter.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property ZStream As ZStream
C#
public ZStream ZStream {get;}

Remarks
This property is useful only in advanced applications that need to customize the low-level
behavior of the compressor. It is not needed in common applications.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1ZStreamWriter Class
C1ZStreamWriter Members

ZipFileException
Exception thrown when trying to open an invalid Zip file.

Object Model

Syntax
Visual Basic (Declaration)
Public Class ZipFileException
Inherits System.IO.IOException
C#
public class ZipFileException : System.IO.IOException

Inheritance Hierarchy
System.Object
System.Exception
System.SystemException
System.IO.IOException
C1.C1Zip.ZipFileException

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZipFileException Members
C1.C1Zip Namespace

Overview
Exception thrown when trying to open an invalid Zip file.

Object Model

Syntax
Visual Basic (Declaration)
Public Class ZipFileException
Inherits System.IO.IOException
C#
public class ZipFileException : System.IO.IOException

Inheritance Hierarchy
System.Object
System.Exception
System.SystemException
System.IO.IOException
C1.C1Zip.ZipFileException

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZipFileException Members
C1.C1Zip Namespace

Members
Properties Methods

The following tables list the members exposed by ZipFileException.

Public Constructors

Name

Description

ZipFileException Constructor Overloaded.


Top

Public Properties
Name

Description

Data

(Inherited from System.Exception)

HelpLink

(Inherited from System.Exception)

HResult

(Inherited from System.Exception)

InnerException

(Inherited from System.Exception)

Message

(Inherited from System.Exception)

Source

(Inherited from System.Exception)

StackTrace

(Inherited from System.Exception)

TargetSite

(Inherited from System.Exception)

Top

Public Methods
Name

Description

GetBaseException (Inherited from System.Exception)

Top

GetObjectData

(Inherited from System.Exception)

GetType

(Inherited from System.Exception)

ToString

(Inherited from System.Exception)

See Also
Reference
ZipFileException Class
C1.C1Zip Namespace

ZipFileException Constructor

Overload List
Overload

Description

ZipFileException Constructor(String)

Initializes a new instance of a


ZipFileException.

ZipFileException Constructor(String,String)

Initializes a new instance of a


ZipFileException.

ZipFileException Constructor(String,String,Exception) Initializes a new instance of a


ZipFileException.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZipFileException Class
ZipFileException Members

ZipFileException Constructor(String)
Message that describes the exception.
Initializes a new instance of a ZipFileException.

Syntax
Visual Basic (Declaration)
Public Function New( _

ByVal msg As String _


)
C#
public ZipFileException(
string msg
)

Parameters
msg
Message that describes the exception.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
ZipFileException Class
ZipFileException Members
Overload List

ZipFileException Constructor(String,String)
Message that describes the exception.
Name of the file that caused the exception.
Initializes a new instance of a ZipFileException.

Syntax
Visual Basic (Declaration)
Public Function New( _
ByVal msg As String, _
ByVal filename As String _
)
C#
public ZipFileException(

string msg,
string filename
)

Parameters
msg
Message that describes the exception.
filename
Name of the file that caused the exception.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
ZipFileException Class
ZipFileException Members
Overload List

ZipFileException Constructor(String,String,Exception)
Message that describes the exception.
Name of the file that caused the exception.
Inner exception.
Initializes a new instance of a ZipFileException.

Syntax
Visual Basic (Declaration)
Public Function New( _
ByVal msg As String, _
ByVal filename As String, _
ByVal innerException As Exception _
)
C#

public ZipFileException(
string msg,
string filename,
Exception innerException
)

Parameters
msg
Message that describes the exception.
filename
Name of the file that caused the exception.
innerException
Inner exception.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2
(Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
ZipFileException Class
ZipFileException Members
Overload List

ZipProgressEventArgs
Provides data for the C1ZipFile.Progress event of a C1ZipFile.

Object Model

Syntax
Visual Basic (Declaration)
Public Class ZipProgressEventArgs
Inherits System.EventArgs

C#
public class ZipProgressEventArgs : System.EventArgs

Inheritance Hierarchy
System.Object
System.EventArgs
C1.C1Zip.ZipProgressEventArgs

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZipProgressEventArgs Members
C1.C1Zip Namespace

Overview
Provides data for the C1ZipFile.Progress event of a C1ZipFile.

Object Model

Syntax
Visual Basic (Declaration)
Public Class ZipProgressEventArgs
Inherits System.EventArgs
C#
public class ZipProgressEventArgs : System.EventArgs

Inheritance Hierarchy
System.Object
System.EventArgs
C1.C1Zip.ZipProgressEventArgs

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZipProgressEventArgs Members
C1.C1Zip Namespace

Members
Properties

The following tables list the members exposed by ZipProgressEventArgs.

Public Properties
Name

Description

Cancel

Set to true to cancel the current operation.

FileLength

Gets the length of the file being compressed or expanded.

FileLengthLong

Gets the length of the file being compressed or expanded.

FileName

Gets the name of the file being compressed or expanded.

Position

Gets the current position into the stream.

PositionLong

Gets the current position into the stream.

Top

See Also
Reference
ZipProgressEventArgs Class
C1.C1Zip Namespace

Properties
>
Name

Description

Cancel

Set to true to cancel the current operation.

FileLength

Gets the length of the file being compressed or expanded.

FileLengthLong

Gets the length of the file being compressed or expanded.

FileName

Gets the name of the file being compressed or expanded.

Position

Gets the current position into the stream.

PositionLong

Gets the current position into the stream.

Top

See Also
Reference
ZipProgressEventArgs Class
C1.C1Zip Namespace

Cancel Property
Set to true to cancel the current operation.

Syntax
Visual Basic (Declaration)
Public Property Cancel As Boolean
C#
public bool Cancel {get; set;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference

ZipProgressEventArgs Class
ZipProgressEventArgs Members

FileLength Property
Gets the length of the file being compressed or expanded.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property FileLength As Integer
C#
public int FileLength {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZipProgressEventArgs Class
ZipProgressEventArgs Members

FileLengthLong Property
Gets the length of the file being compressed or expanded.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property FileLengthLong As Long
C#
public long FileLengthLong {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZipProgressEventArgs Class
ZipProgressEventArgs Members

FileName Property
Gets the name of the file being compressed or expanded.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property FileName As String
C#
public string FileName {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZipProgressEventArgs Class
ZipProgressEventArgs Members

Position Property
Gets the current position into the stream.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property Position As Integer
C#
public int Position {get;}

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZipProgressEventArgs Class
ZipProgressEventArgs Members

PositionLong Property
Gets the current position into the stream.

Syntax
Visual Basic (Declaration)
Public ReadOnly Property PositionLong As Long
C#
public long PositionLong {get;}

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZipProgressEventArgs Class
ZipProgressEventArgs Members

Enumerations
CompressionLevelEnum
Specifies the level of compression to be applied when adding entries to a C1ZipFile.

Syntax
Visual Basic (Declaration)

Public Enum CompressionLevelEnum


Inherits System.Enum
C#
public enum CompressionLevelEnum : System.Enum

Members
Member

Description

BestCompression

Highest compression, low speed.

BestSpeed

Low compression, highest speed.

DefaultCompression High compression, high speed.


NoCompression

No Compression.

Inheritance Hierarchy
System.Object
System.ValueType
System.Enum
C1.C1Zip.CompressionLevelEnum

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
C1.C1Zip Namespace

Delegates
ZipProgressEventHandler
Represents the method that will handle the C1ZipFile.Progress event of a C1ZipFile.

Syntax

Visual Basic (Declaration)


Public Delegate Sub ZipProgressEventHandler( _
ByVal sender As Object, _
ByVal e As ZipProgressEventArgs _
)
C#
public delegate void ZipProgressEventHandler(
object sender,
ZipProgressEventArgs e
)

Parameters
sender
e

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
ZipProgressEventHandler Members
C1.C1Zip Namespace

C1.C1Zip.ZLib Namespace
Overview
Classes
Class

Description

ZStream

ZStream is the most flexible and hardest to use class in the C1.C1Zip
assembly. It contains a C# implementation of ZLIB's zstream object,
which is a general purpose compressor and decompressor.

ZStreamException The exception that is thrown when reading or writing to a compressed


stream fails.

See Also
Reference
C1.C1Zip.4 Assembly

Classes
ZStream
ZStream is the most flexible and hardest to use class in the C1.C1Zip assembly. It contains a C#
implementation of ZLIB's zstream object, which is a general purpose compressor and
decompressor.

Object Model

Syntax
Visual Basic (Declaration)
Public Class ZStream
C#
public class ZStream

Remarks
In most cases, you should be able to use the C1.C1Zip.C1ZStreamReader and
C1.C1Zip.C1ZStreamWriter classes instead of ZStream. These classes provide friendly and easyto-use wrappers that hide the ZLIB complexity.
Use ZStream only if you are familiar with ZLIB and need control over the low-level aspects of
the data compression or decompression process (e.g., to provide your own buffers or
compression dictionaries).
If you choose to use ZStream directly and need technical support, please check out the detailed
documentation, sample, and articles available at http://www.info-zip.org/ or
http://www.gzip.org/, the official zlib sites.
ZLIB is an open-source, patent-free library created by Jean-Loup Gailly and Mark Adler.

Inheritance Hierarchy
System.Object
C1.C1Zip.ZLib.ZStream

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Members
C1.C1Zip.ZLib Namespace

Overview
ZStream is the most flexible and hardest to use class in the C1.C1Zip assembly. It contains a C#
implementation of ZLIB's zstream object, which is a general purpose compressor and
decompressor.

Object Model

Syntax
Visual Basic (Declaration)
Public Class ZStream
C#
public class ZStream

Remarks
In most cases, you should be able to use the C1.C1Zip.C1ZStreamReader and
C1.C1Zip.C1ZStreamWriter classes instead of ZStream. These classes provide friendly and easyto-use wrappers that hide the ZLIB complexity.
Use ZStream only if you are familiar with ZLIB and need control over the low-level aspects of
the data compression or decompression process (e.g., to provide your own buffers or
compression dictionaries).

If you choose to use ZStream directly and need technical support, please check out the detailed
documentation, sample, and articles available at http://www.info-zip.org/ or
http://www.gzip.org/, the official zlib sites.
ZLIB is an open-source, patent-free library created by Jean-Loup Gailly and Mark Adler.

Inheritance Hierarchy
System.Object
C1.C1Zip.ZLib.ZStream

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Members
C1.C1Zip.ZLib Namespace

Members
Fields Methods

The following tables list the members exposed by ZStream.

Public Constructors
Name

Description

ZStream Constructor Overloaded.


Top

Public Fields
Name

Description

adler

Current checksum value (Adler or CRC32).

avail_in

Number of bytes available in the input buffer.

avail_out

Number of free bytes remaining in output buffer.

msg

Description of the last error (null if no errors).

next_in

Input buffer.

next_in_index

Position of cursor into input buffer.

next_out

Output buffer.

next_out_index

Position of cursor into the output buffer.

total_in

Total number of input bytes read so far.

total_out

Total number of bytes output so far.

Z_BUF_ERROR

No progress possible or no room in output buffer.

Z_DATA_ERROR

Input data is corrupted (wrong format or checksum).

Z_ERRNO

File error.

Z_MEM_ERROR

Not enough memory.

Z_NEED_DICT

A preset dictionary is needed at this point.

Z_OK

No error.

Z_STREAM_END

End of stream detected.

Z_STREAM_ERROR Stream structure is inconsistent (input/output buffers are null for


example).
Z_VERSION_ERROR Incompatible ZLIB version.
Top

Public Methods

Name

Description

deflate

Compresses as much data as possible, and stops when the input


buffer becomes empty or the output buffer becomes full.

deflateEnd

Frees all dynamically allocated data structures for this stream, discards
any unprocessed input, and does not flush any pending output.

deflateInit

Overloaded. Initializes the internal stream state for compression.

deflateParams

Dynamically updates the compression level and compression


strategy.

deflateSetDictionary Initializes the compression dictionary from the given byte sequence
without producing any compressed output.
inflate

Decompresses as much data as possible until the input buffer is


exhausted or the output buffer is full.

inflateEnd

Frees all dynamically allocated data structures for this stream, discards
any unprocessed input, and does not flush any pending output.

inflateInit

Overloaded. Initializes the internal stream state for decompression.

inflateSetDictionary Initializes the decompression dictionary from the given uncompressed


byte sequence.
inflateSync

Skips invalid compressed data until a full flush point is found, or until
all available input is skipped. No output is provided.

Top

See Also
Reference
ZStream Class
C1.C1Zip.ZLib Namespace

ZStream Constructor

Overload List
Overload

Description

ZStream Constructor()

Initializes a new instance of the ZStream class using an Adler


checksum.

ZStream Constructor(Boolean) Initializes a new instance of the ZStream class.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

ZStream Constructor()
Initializes a new instance of the ZStream class using an Adler checksum.

Syntax
Visual Basic (Declaration)
Public Function New()
C#
public ZStream()

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference

ZStream Class
ZStream Members
Overload List

ZStream Constructor(Boolean)
True to use a CRC32 checksum, False to use an Adler checksum.
Initializes a new instance of the ZStream class.

Syntax
Visual Basic (Declaration)
Public Function New( _
ByVal crc32 As Boolean _
)
C#
public ZStream(
bool crc32
)

Parameters
crc32
True to use a CRC32 checksum, False to use an Adler checksum.

Remarks
CRC32 checksums are the standard used in zip files. Adler checksums are the default used
by ZLIB. Adler checksums are faster to calculate, but are not compatible with the zip
format.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members
Overload List

Methods
%%scrap%%
" -->
For a list of all members of this type, see ZStream members.

Public Methods
Name

Description

deflate

Compresses as much data as possible, and stops when the input


buffer becomes empty or the output buffer becomes full.

deflateEnd

Frees all dynamically allocated data structures for this stream, discards
any unprocessed input, and does not flush any pending output.

deflateInit

Overloaded. Initializes the internal stream state for compression.

deflateParams

Dynamically updates the compression level and compression


strategy.

deflateSetDictionary Initializes the compression dictionary from the given byte sequence
without producing any compressed output.
inflate

Decompresses as much data as possible until the input buffer is


exhausted or the output buffer is full.

inflateEnd

Frees all dynamically allocated data structures for this stream, discards
any unprocessed input, and does not flush any pending output.

inflateInit

Overloaded. Initializes the internal stream state for decompression.

inflateSetDictionary Initializes the decompression dictionary from the given uncompressed


byte sequence.
inflateSync

Skips invalid compressed data until a full flush point is found, or until
all available input is skipped. No output is provided.

Top

See Also
Reference
ZStream Class
C1.C1Zip.ZLib Namespace

deflate Method
Non-zero to force some data to be flushed into the output buffer.
Compresses as much data as possible, and stops when the input buffer becomes empty or the
output buffer becomes full.

Syntax
Visual Basic (Declaration)
Public Function deflate( _
ByVal flush As Integer _
) As Integer
C#
public int deflate(
int flush
)

Parameters
flush
Non-zero to force some data to be flushed into the output buffer.

Return Value
Zero on success, an error code on failure.

Remarks
deflate performs one or both of the following actions:
1. Compress more input starting at next_in and update next_in and avail_in accordingly.
If not all input can be processed (because there is not enough room in the output buffer),
next_in and avail_in are updated and processing will resume at this point for the next call
to deflate.
2. Provide more output starting at next_out and update next_out and avail_out
accordingly. This action is forced if the parameter flush is non zero. Forcing flush
frequently degrades the compression ratio, so this parameter should be set only when

necessary (in interactive applications). Some output may be provided even if flush is not
set
This method may introduce some output latency (reading input without producing any
output) except when forced to flush.
If deflate returns with avail_out == 0, this method must be called again with the same
value of the flush parameter and more output space until the flush is complete (deflate
returns with avail_out != 0).

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

deflateEnd Method
Frees all dynamically allocated data structures for this stream, discards any unprocessed input,
and does not flush any pending output.

Syntax
Visual Basic (Declaration)
Public Function deflateEnd() As Integer
C#
public int deflateEnd()

Return Value
Zero on success, an error code on failure.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also

Reference
ZStream Class
ZStream Members

deflateInit Method
Initializes the internal stream state for compression.

Overload List
Overload

Description

deflateInit(Int32)

Initializes the internal stream state for compression.

deflateInit(Int32,Int32) Initializes the internal stream state for compression.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

deflateInit(Int32) Method
Compression level between zero and nine (0-9).
Initializes the internal stream state for compression.

Syntax
Visual Basic (Declaration)
Public Overloads Function deflateInit( _
ByVal level As Integer _
) As Integer
C#
public int deflateInit(
int level

Parameters
level
Compression level between zero and nine (0-9).

Return Value
Zero on success, an error code on failure.

Remarks
Compression level 1 gives best speed, 9 gives best compression.
Compression level zero gives no compression at all (the input data is simply copied a
block at a time).
The default compression level is 6, which provides a compromise between speed and
compression.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members
Overload List

deflateInit(Int32,Int32) Method
Compression level between zero and nine (0-9).
Size of the LZ77 sliding compression window in bits (the default value is 15 bits).
Initializes the internal stream state for compression.

Syntax
Visual Basic (Declaration)
Public Overloads Function deflateInit( _
ByVal level As Integer, _

ByVal bits As Integer _


) As Integer
C#
public int deflateInit(
int level,
int bits
)

Parameters
level
Compression level between zero and nine (0-9).
bits
Size of the LZ77 sliding compression window in bits (the default value is 15 bits).

Return Value
Zero on success, an error code on failure.

Remarks
Compression level 1 gives best speed, 9 gives best compression.
Compression level zero gives no compression at all (the input data is simply copied a
block at a time).
The default compression level is 6, which provides a compromise between speed and
compression.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members
Overload List

deflateParams Method
Compression level between zero and nine (0-9).
Compression strategy (0-2).
Dynamically updates the compression level and compression strategy.

Syntax
Visual Basic (Declaration)
Public Function deflateParams( _
ByVal level As Integer, _
ByVal strategy As Integer _
) As Integer
C#
public int deflateParams(
int level,
int strategy
)

Parameters
level
Compression level between zero and nine (0-9).
strategy
Compression strategy (0-2).

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

deflateSetDictionary Method
Data in the dictionary.

Number of bytes in the dictionary.


Initializes the compression dictionary from the given byte sequence without producing any
compressed output.

Syntax
Visual Basic (Declaration)
Public Function deflateSetDictionary( _
ByVal dictionary() As Byte, _
ByVal dictLength As Integer _
) As Integer
C#
public int deflateSetDictionary(
byte[] dictionary,
int dictLength
)

Parameters
dictionary
Data in the dictionary.
dictLength
Number of bytes in the dictionary.

Return Value
Zero on success, an error code on failure.

Remarks
This method must be called immediately after deflateInit(Int32), before any call to
deflate.
The compressor and decompressor must use exactly the same dictionary (see
inflateSetDictionary).

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

inflate Method
How to flush data into the output buffer (default value is 2).
Decompresses as much data as possible until the input buffer is exhausted or the output buffer
is full.

Syntax
Visual Basic (Declaration)
Public Function inflate( _
ByVal flush As Integer _
) As Integer
C#
public int inflate(
int flush
)

Parameters
flush
How to flush data into the output buffer (default value is 2).

Return Value
Z_OK if some progress has been made (more input processed or more output produced),
Z_STREAM_END if the end of the compressed data has been reached and all
uncompressed output has been produced, Z_NEED_DICT if a preset dictionary is needed
at this point, Z_DATA_ERROR if the input data was corrupted (input stream not
conforming to the zlib format or incorrect checksum), Z_STREAM_ERROR if the stream
structure was inconsistent (for example if next_in or next_out was null), Z_MEM_ERROR if
there was not enough memory, Z_BUF_ERROR if no progress is possible or if there was
not enough room in the output buffer when Z_FINISH is used.

Remarks
inflate performs one or both of the following actions:

1. Decompress more input starting at next_in and update next_in and avail_in
accordingly. If not all input can be processed (because there is not enough room in the
output buffer), next_in is updated and processing will resume at this point for the next call
to inflate.
2. Provide more output starting at next_out and update next_out and avail_out
accordingly. inflate provides as much output as possible, until there is no more input data
or no more space in the output buffer.
Before the call to inflate, the application should ensure that at least one of the actions is
possible, by providing more input and/or consuming more output, and updating the
next_* and avail_* values accordingly.
If inflate returns Zero and avail_out == 0, it must be called again after making room in
the output buffer because there might be more output pending.
The application can consume the uncompressed output when it wants, for example when
the output buffer is full (avail_out == 0), or after each call of inflate.
This method may introduce some output latency (reading input without producing any
output) except when forced to flush.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

inflateEnd Method
Frees all dynamically allocated data structures for this stream, discards any unprocessed input,
and does not flush any pending output.

Syntax
Visual Basic (Declaration)
Public Function inflateEnd() As Integer
C#
public int inflateEnd()

Return Value
Zero on success, an error code on failure.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

inflateInit Method
Initializes the internal stream state for decompression.

Overload List
Overload

Description

inflateInit()

Initializes the internal stream state for decompression.

inflateInit(Int32)

Initializes the internal stream state for decompression.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

inflateInit() Method
Initializes the internal stream state for decompression.

Syntax

Visual Basic (Declaration)


Public Overloads Function inflateInit() As Integer
C#
public int inflateInit()

Return Value
Zero on success, an error code on failure.

Remarks
The fields next_in and avail_in must be initialized before by the caller.
inflateInit does not perform any decompression apart from reading the zlib header if present:
data decompression is done by the inflate method. Therefore, the next_in and avail_in may be
modified, but next_out and avail_out are unchanged.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members
Overload List

inflateInit(Int32) Method
Size of the LZ77 sliding compression window in bits (the default value is 15 bits).
Initializes the internal stream state for decompression.

Syntax
Visual Basic (Declaration)
Public Overloads Function inflateInit( _
ByVal bits As Integer _
) As Integer

C#
public int inflateInit(
int bits
)

Parameters
bits
Size of the LZ77 sliding compression window in bits (the default value is 15 bits).

Return Value
Zero on success, an error code on failure.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows
Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported
with SP1 or later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members
Overload List

inflateSetDictionary Method
Data in the dictionary.
Number of bytes in the dictionary.
Initializes the decompression dictionary from the given uncompressed byte sequence.

Syntax
Visual Basic (Declaration)
Public Function inflateSetDictionary( _
ByVal dictionary() As Byte, _
ByVal dictLength As Integer _
) As Integer
C#

public int inflateSetDictionary(


byte[] dictionary,
int dictLength
)

Parameters
dictionary
Data in the dictionary.
dictLength
Number of bytes in the dictionary.

Return Value
Zero on success, an error code on failure.

Remarks
This method must be called immediately after a call of inflate if this call returned
Z_NEED_DICT. The dictionary chosen by the compressor can be determined from
the Adler32 value returned by this call to inflate.
The compressor and decompressor must use exactly the same dictionary (see the
deflateSetDictionary method).

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3,
Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server
Core supported with SP1 or later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

inflateSync Method
Skips invalid compressed data until a full flush point is found, or until all available input is
skipped. No output is provided.

Syntax
Visual Basic (Declaration)

Public Function inflateSync() As Integer


C#
public int inflateSync()

Return Value
Zero on success, an error code on failure.

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

Fields
%%scrap%%
" -->
For a list of all members of this type, see ZStream members.

Public Fields
Name

Description

adler

Current checksum value (Adler or CRC32).

avail_in

Number of bytes available in the input buffer.

avail_out

Number of free bytes remaining in output buffer.

msg

Description of the last error (null if no errors).

next_in

Input buffer.

next_in_index

Position of cursor into input buffer.

next_out

Output buffer.

next_out_index

Position of cursor into the output buffer.

total_in

Total number of input bytes read so far.

total_out

Total number of bytes output so far.

Z_BUF_ERROR

No progress possible or no room in output buffer.

Z_DATA_ERROR

Input data is corrupted (wrong format or checksum).

Z_ERRNO

File error.

Z_MEM_ERROR

Not enough memory.

Z_NEED_DICT

A preset dictionary is needed at this point.

Z_OK

No error.

Z_STREAM_END

End of stream detected.

Z_STREAM_ERROR Stream structure is inconsistent (input/output buffers are null for


example).
Z_VERSION_ERROR Incompatible ZLIB version.
Top

See Also
Reference
ZStream Class
C1.C1Zip.ZLib Namespace

adler Field
Current checksum value (Adler or CRC32).

Syntax

Visual Basic (Declaration)


Public adler As Long
C#
public long adler

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

avail_in Field
Number of bytes available in the input buffer.

Syntax
Visual Basic (Declaration)
Public avail_in As Integer
C#
public int avail_in

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

avail_out Field
Number of free bytes remaining in output buffer.

Syntax
Visual Basic (Declaration)
Public avail_out As Integer
C#
public int avail_out

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

msg Field
Description of the last error (null if no errors).

Syntax
Visual Basic (Declaration)
Public msg As String
C#
public string msg

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also

Reference
ZStream Class
ZStream Members

next_in Field
Input buffer.

Syntax
Visual Basic (Declaration)
Public next_in As Byte()
C#
public byte[] next_in

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

next_in_index Field
Position of cursor into input buffer.

Syntax
Visual Basic (Declaration)
Public next_in_index As Integer
C#
public int next_in_index

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

next_out Field
Output buffer.

Syntax
Visual Basic (Declaration)
Public next_out As Byte()
C#
public byte[] next_out

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

next_out_index Field
Position of cursor into the output buffer.

Syntax
Visual Basic (Declaration)
Public next_out_index As Integer

C#
public int next_out_index

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

total_in Field
Total number of input bytes read so far.

Syntax
Visual Basic (Declaration)
Public total_in As Long
C#
public long total_in

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

total_out Field
Total number of bytes output so far.

Syntax

Visual Basic (Declaration)


Public total_out As Long
C#
public long total_out

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

Z_BUF_ERROR Field
No progress possible or no room in output buffer.

Syntax
Visual Basic (Declaration)
Public Const Z_BUF_ERROR As Integer
C#
public const int Z_BUF_ERROR

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

Z_DATA_ERROR Field
Input data is corrupted (wrong format or checksum).

Syntax
Visual Basic (Declaration)
Public Const Z_DATA_ERROR As Integer
C#
public const int Z_DATA_ERROR

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

Z_ERRNO Field
File error.

Syntax
Visual Basic (Declaration)
Public Const Z_ERRNO As Integer
C#
public const int Z_ERRNO

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also

Reference
ZStream Class
ZStream Members

Z_MEM_ERROR Field
Not enough memory.

Syntax
Visual Basic (Declaration)
Public Const Z_MEM_ERROR As Integer
C#
public const int Z_MEM_ERROR

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

Z_NEED_DICT Field
A preset dictionary is needed at this point.

Syntax
Visual Basic (Declaration)
Public Const Z_NEED_DICT As Integer
C#
public const int Z_NEED_DICT

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

Z_OK Field
No error.

Syntax
Visual Basic (Declaration)
Public Const Z_OK As Integer
C#
public const int Z_OK

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

Z_STREAM_END Field
End of stream detected.

Syntax
Visual Basic (Declaration)
Public Const Z_STREAM_END As Integer

C#
public const int Z_STREAM_END

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

Z_STREAM_ERROR Field
Stream structure is inconsistent (input/output buffers are null for example).

Syntax
Visual Basic (Declaration)
Public Const Z_STREAM_ERROR As Integer
C#
public const int Z_STREAM_ERROR

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

Z_VERSION_ERROR Field
Incompatible ZLIB version.

Syntax

Visual Basic (Declaration)


Public Const Z_VERSION_ERROR As Integer
C#
public const int Z_VERSION_ERROR

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStream Class
ZStream Members

ZStreamException
The exception that is thrown when reading or writing to a compressed stream fails.

Object Model

Syntax
Visual Basic (Declaration)
Public Class ZStreamException
Inherits System.ApplicationException
C#
public class ZStreamException : System.ApplicationException

Inheritance Hierarchy
System.Object
System.Exception
System.ApplicationException
C1.C1Zip.ZLib.ZStreamException

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also
Reference
ZStreamException Members
C1.C1Zip.ZLib Namespace

Overview
The exception that is thrown when reading or writing to a compressed stream fails.

Object Model

Syntax
Visual Basic (Declaration)
Public Class ZStreamException
Inherits System.ApplicationException
C#
public class ZStreamException : System.ApplicationException

Inheritance Hierarchy
System.Object
System.Exception
System.ApplicationException
C1.C1Zip.ZLib.ZStreamException

Requirements
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server
2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or
later), Windows Server 2003 SP2

See Also

Reference
ZStreamException Members
C1.C1Zip.ZLib Namespace

Members
Properties Methods

The following tables list the members exposed by ZStreamException.

Public Properties
Name

Description

Data

(Inherited from System.Exception)

HelpLink

(Inherited from System.Exception)

HResult

(Inherited from System.Exception)

InnerException

(Inherited from System.Exception)

Message

(Inherited from System.Exception)

Source

(Inherited from System.Exception)

StackTrace

(Inherited from System.Exception)

TargetSite

(Inherited from System.Exception)

Top

Public Methods
Name

Description

GetBaseException (Inherited from System.Exception)


GetObjectData

(Inherited from System.Exception)

GetType

(Inherited from System.Exception)

ToString

(Inherited from System.Exception)

Top

See Also
Reference
ZStreamException Class
C1.C1Zip.ZLib Namespace

You might also like