C# Class Crisis.Ionic.Zip.ZipFile

Mostrar archivo Open project: teeknofil/Crisis-Wordlist-Generator Class Usage Examples

Private Properties

Property Type Description
AddOrUpdateDirectoryImpl ZipEntry
AddOrUpdateDirectoryImpl ZipEntry
AfterAddEntry void
CleanupAfterSaveOperation void
DeleteFileWithRetry void
EnsureendInSlash string
ExtractResourceToFile void
GenerateTempPathname string
GetNewEnum System.Collections.IEnumerator
InternalAddEntry void
NotifyEntriesSaveComplete void
OnAddCompleted void
OnAddStarted void
OnExtractAllCompleted void
OnExtractAllStarted void
OnExtractBlock bool
OnExtractEntry void
OnExtractExisting bool
OnReadBytes void
OnReadCompleted void
OnReadEntry void
OnReadStarted void
OnSaveBlock bool
OnSaveCompleted void
OnSaveEntry void
OnSaveEvent void
OnSaveStarted void
OnSingleEntryExtract bool
OnZipErrorSaving bool
Read ZipFile
Read ZipFile
ReadCentralDirectory void
ReadCentralDirectoryFooter void
ReadFirstFourBytes uint
ReadIntoInstance void
ReadIntoInstance_Orig void
ReadZipFileComment void
RemoveEntryForUpdate void
RemoveTempFile void
ReplaceEx string
ReplaceLeadingDirectory string
System System.Collections.IEnumerator
Zip64SeekToCentralDirectory void
_AddOrUpdateSelectedFiles void
_InternalAddEntry ZipEntry
_InternalExtractAll void
_SaveSfxStub void

Public Methods

Method Description
AddDirectory ( string directoryName ) : ZipEntry

Adds the contents of a filesystem directory to a Zip file archive.

The name of the directory may be a relative path or a fully-qualified path. Any files within the named directory are added to the archive. Any subdirectories within the named directory are also added to the archive, recursively.

Top-level entries in the named directory will appear as top-level entries in the zip archive. Entries in subdirectories in the named directory will result in entries in subdirectories in the zip archive.

If you want the entries to appear in a containing directory in the zip archive itself, then you should call the AddDirectory() overload that allows you to explicitly specify a directory path for use in the archive.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to each ZipEntry added.

AddDirectory ( string directoryName, string directoryPathInArchive ) : ZipEntry

Adds the contents of a filesystem directory to a Zip file archive, overriding the path to be used for entries in the archive.

The name of the directory may be a relative path or a fully-qualified path. The add operation is recursive, so that any files or subdirectories within the name directory are also added to the archive.

Top-level entries in the named directory will appear as top-level entries in the zip archive. Entries in subdirectories in the named directory will result in entries in subdirectories in the zip archive.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to each ZipEntry added.

AddDirectoryByName ( string directoryNameInArchive ) : ZipEntry

Creates a directory in the zip archive.

Use this when you want to create a directory in the archive but there is no corresponding filesystem representation for that directory.

You will probably not need to do this in your code. One of the only times you will want to do this is if you want an empty directory in the zip archive. The reason: if you add a file to a zip archive that is stored within a multi-level directory, all of the directory tree is implicitly created in the zip archive.

AddEntry ( string entryName, OpenDelegate opener, CloseDelegate closer ) : ZipEntry

Add an entry, for which the application will provide a stream containing the entry data, on a just-in-time basis.

In cases where the application wishes to open the stream that holds the content for the ZipEntry, on a just-in-time basis, the application can use this method. The application provides an opener delegate that will be called by the DotNetZip library to obtain a readable stream that can be read to get the bytes for the given entry. Typically, this delegate opens a stream. Optionally, the application can provide a closer delegate as well, which will be called by DotNetZip when all bytes have been read from the entry.

These delegates are called from within the scope of the call to ZipFile.Save().

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

AddEntry ( string entryName, Stream stream ) : ZipEntry

Create an entry in the ZipFile using the given Stream as input. The entry will have the given filename.

The application should provide an open, readable stream; in this case it will be read during the call to ZipFile.Save() or one of its overloads.

The passed stream will be read from its current position. If necessary, callers should set the position in the stream before calling AddEntry(). This might be appropriate when using this method with a MemoryStream, for example.

In cases where a large number of streams will be added to the ZipFile, the application may wish to avoid maintaining all of the streams open simultaneously. To handle this situation, the application should use the AddEntry(string, OpenDelegate, CloseDelegate) overload.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

AddEntry ( string entryName, WriteDelegate writer ) : ZipEntry

Add a ZipEntry for which content is written directly by the application.

When the application needs to write the zip entry data, use this method to add the ZipEntry. For example, in the case that the application wishes to write the XML representation of a DataSet into a ZipEntry, the application can use this method to do so.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

About progress events: When using the WriteDelegate, DotNetZip does not issue any SaveProgress events with EventType = Saving_EntryBytesRead. (This is because it is the application's code that runs in WriteDelegate - there's no way for DotNetZip to know when to issue a EntryBytesRead event.) Applications that want to update a progress bar or similar status indicator should do so from within the WriteDelegate itself. DotNetZip will issue the other SaveProgress events, including Saving_Started, Saving_BeforeWriteEntry, and Saving_AfterWriteEntry.

Note: When you use PKZip encryption, it's normally necessary to compute the CRC of the content to be encrypted, before compressing or encrypting it. Therefore, when using PKZip encryption with a WriteDelegate, the WriteDelegate CAN BE called twice: once to compute the CRC, and the second time to potentially compress and encrypt. Surprising, but true. This is because PKWARE specified that the encryption initialization data depends on the CRC. If this happens, for each call of the delegate, your application must stream the same entry data in its entirety. If your application writes different data during the second call, it will result in a corrupt zip file.

The double-read behavior happens with all types of entries, not only those that use WriteDelegate. It happens if you add an entry from a filesystem file, or using a string, or a stream, or an opener/closer pair. But in those cases, DotNetZip takes care of reading twice; in the case of the WriteDelegate, the application code gets invoked twice. Be aware.

As you can imagine, this can cause performance problems for large streams, and it can lead to correctness problems when you use a WriteDelegate. This is a pretty big pitfall. There are two ways to avoid it. First, and most preferred: don't use PKZIP encryption. If you use the WinZip AES encryption, this problem doesn't occur, because the encryption protocol doesn't require the CRC up front. Second: if you do choose to use PKZIP encryption, write out to a non-seekable stream (like standard output, or the Response.OutputStream in an ASP.NET application). In this case, DotNetZip will use an alternative encryption protocol that does not rely on the CRC of the content. This also implies setting bit 3 in the zip entry, which still presents problems for some zip tools.

In the future I may modify DotNetZip to *always* use bit 3 when PKZIP encryption is in use. This seems like a win overall, but there will be some work involved. If you feel strongly about it, visit the DotNetZip forums and vote up the Workitem tracking this issue.

AddEntry ( string entryName, byte byteContent ) : ZipEntry

Add an entry into the zip archive using the given filename and directory path within the archive, and the given content for the file. No file is created in the filesystem.

AddEntry ( string entryName, string content ) : ZipEntry

Adds a named entry into the zip archive, taking content for the entry from a string.

Calling this method creates an entry using the given fileName and directory path within the archive. There is no need for a file by the given name to exist in the filesystem; the name is used within the zip archive only. The content for the entry is encoded using the default text encoding for the machine, or on Silverlight, using UTF-8.

AddEntry ( string entryName, string content, System encoding ) : ZipEntry

Adds a named entry into the zip archive, taking content for the entry from a string, and using the specified text encoding.

Calling this method creates an entry using the given fileName and directory path within the archive. There is no need for a file by the given name to exist in the filesystem; the name is used within the zip archive only.

The content for the entry, a string value, is encoded using the given text encoding. A BOM (byte-order-mark) is emitted into the file, if the Encoding parameter is set for that.

Most Encoding classes support a constructor that accepts a boolean, indicating whether to emit a BOM or not. For example see .

AddFile ( string fileName ) : ZipEntry

Adds a File to a Zip file archive.

This call collects metadata for the named file in the filesystem, including the file attributes and the timestamp, and inserts that metadata into the resulting ZipEntry. Only when the application calls Save() on the ZipFile, does DotNetZip read the file from the filesystem and then write the content to the zip file archive.

This method will throw an exception if an entry with the same name already exists in the ZipFile.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

AddFile ( string fileName, String directoryPathInArchive ) : ZipEntry

Adds a File to a Zip file archive, potentially overriding the path to be used within the zip archive.

The file added by this call to the ZipFile is not written to the zip file archive until the application calls Save() on the ZipFile.

This method will throw an exception if an entry with the same name already exists in the ZipFile.

This version of the method allows the caller to explicitly specify the directory path to be used in the archive.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

AddFiles ( System fileNames ) : void

This method adds a set of files to the ZipFile.

Use this method to add a set of files to the zip archive, in one call. For example, a list of files received from System.IO.Directory.GetFiles() can be added to a zip archive in one call.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to each ZipEntry added.

AddFiles ( System fileNames, String directoryPathInArchive ) : void

Adds a set of files to the ZipFile, using the specified directory path in the archive.

Any directory structure that may be present in the filenames contained in the list is "flattened" in the archive. Each file in the list is added to the archive in the specified top-level directory.

For ZipFile properties including , Password, , , , , and , their respective values at the time of this call will be applied to each ZipEntry added.

AddFiles ( System fileNames, bool preserveDirHierarchy, String directoryPathInArchive ) : void

Adds a set of files to the ZipFile, using the specified directory path in the archive, and preserving the full directory structure in the filenames.

Think of the directoryPathInArchive as a "root" or base directory used in the archive for the files that get added. when preserveDirHierarchy is true, the hierarchy of files found in the filesystem will be placed, with the hierarchy intact, starting at that root in the archive. When preserveDirHierarchy is false, the path hierarchy of files is flattned, and the flattened set of files gets placed in the root within the archive as specified in directoryPathInArchive.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to each ZipEntry added.

AddItem ( String fileOrDirectoryName, String directoryPathInArchive ) : ZipEntry

Adds an item, either a file or a directory, to a zip file archive, explicitly specifying the directory path to be used in the archive.

If adding a directory, the add is recursive on all files and subdirectories contained within it.

The name of the item may be a relative path or a fully-qualified path. The item added by this call to the ZipFile is not read from the disk nor written to the zip file archive until the application calls Save() on the ZipFile.

This version of the method allows the caller to explicitly specify the directory path to be used in the archive, which would override the "natural" path of the filesystem file.

Encryption will be used on the file data if the Password has been set on the ZipFile object, prior to calling this method.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

AddItem ( string fileOrDirectoryName ) : ZipEntry

Adds an item, either a file or a directory, to a zip file archive.

This method is handy if you are adding things to zip archive and don't want to bother distinguishing between directories or files. Any files are added as single entries. A directory added through this method is added recursively: all files and subdirectories contained within the directory are added to the ZipFile.

The name of the item may be a relative path or a fully-qualified path. Remember, the items contained in ZipFile instance get written to the disk only when you call ZipFile.Save() or a similar save method.

The directory name used for the file within the archive is the same as the directory name (potentially a relative path) specified in the fileOrDirectoryName.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

AddSelectedFiles ( String selectionCriteria ) : void

Adds to the ZipFile a set of files from the current working directory on disk, that conform to the specified criteria.

This method selects files from the the current working directory matching the specified criteria, and adds them to the ZipFile.

Specify the criteria in statements of 3 elements: a noun, an operator, and a value. Consider the string "name != *.doc" . The noun is "name". The operator is "!=", implying "Not Equal". The value is "*.doc". That criterion, in English, says "all files with a name that does not end in the .doc extension."

Supported nouns include "name" (or "filename") for the filename; "atime", "mtime", and "ctime" for last access time, last modfied time, and created time of the file, respectively; "attributes" (or "attrs") for the file attributes; "size" (or "length") for the file length (uncompressed), and "type" for the type of object, either a file or a directory. The "attributes", "name" and "type" nouns both support = and != as operators. The "size", "atime", "mtime", and "ctime" nouns support = and !=, and >, >=, <, <= as well. The times are taken to be expressed in local time.

Specify values for the file attributes as a string with one or more of the characters H,R,S,A,I,L in any order, implying file attributes of Hidden, ReadOnly, System, Archive, NotContextIndexed, and ReparsePoint (symbolic link) respectively.

To specify a time, use YYYY-MM-DD-HH:mm:ss or YYYY/MM/DD-HH:mm:ss as the format. If you omit the HH:mm:ss portion, it is assumed to be 00:00:00 (midnight).

The value for a size criterion is expressed in integer quantities of bytes, kilobytes (use k or kb after the number), megabytes (m or mb), or gigabytes (g or gb).

The value for a name is a pattern to match against the filename, potentially including wildcards. The pattern follows CMD.exe glob rules: * implies one or more of any character, while ? implies one character. If the name pattern contains any slashes, it is matched to the entire filename, including the path; otherwise, it is matched against only the filename without the path. This means a pattern of "*\*.*" matches all files one directory level deep, while a pattern of "*.*" matches all files in all directories.

To specify a name pattern that includes spaces, use single quotes around the pattern. A pattern of "'* *.*'" will match all files that have spaces in the filename. The full criteria string for that would be "name = '* *.*'" .

The value for a type criterion is either F (implying a file) or D (implying a directory).

Some examples:

criteria Files retrieved name != *.xls any file with an extension that is not .xls name = *.mp3 any file with a .mp3 extension. *.mp3 (same as above) any file with a .mp3 extension. attributes = A all files whose attributes include the Archive bit. attributes != H all files whose attributes do not include the Hidden bit. mtime > 2009-01-01 all files with a last modified time after January 1st, 2009. size > 2gb all files whose uncompressed size is greater than 2gb. type = D all directories in the filesystem.

You can combine criteria with the conjunctions AND or OR. Using a string like "name = *.txt AND size >= 100k" for the selectionCriteria retrieves entries whose names end in .txt, and whose uncompressed size is greater than or equal to 100 kilobytes.

For more complex combinations of criteria, you can use parenthesis to group clauses in the boolean logic. Without parenthesis, the precedence of the criterion atoms is determined by order of appearance. Unlike the C# language, the AND conjunction does not take precendence over the logical OR. This is important only in strings that contain 3 or more criterion atoms. In other words, "name = *.txt and size > 1000 or attributes = H" implies "((name = *.txt AND size > 1000) OR attributes = H)" while "attributes = H OR name = *.txt and size > 1000" evaluates to "((attributes = H OR name = *.txt) AND size > 1000)". When in doubt, use parenthesis.

Using time properties requires some extra care. If you want to retrieve all entries that were last updated on 2009 February 14, specify a time range like so:"mtime >= 2009-02-14 AND mtime < 2009-02-15". Read this to say: all files updated after 12:00am on February 14th, until 12:00am on February 15th. You can use the same bracketing approach to specify any time period - a year, a month, a week, and so on.

The syntax allows one special case: if you provide a string with no spaces, it is treated as a pattern to match for the filename. Therefore a string like "*.xls" will be equivalent to specifying "name = *.xls".

There is no logic in this method that insures that the file inclusion criteria are internally consistent. For example, it's possible to specify criteria that says the file must have a size of less than 100 bytes, as well as a size that is greater than 1000 bytes. Obviously no file will ever satisfy such criteria, but this method does not detect such logical inconsistencies. The caller is responsible for insuring the criteria are sensible.

Using this method, the file selection does not recurse into subdirectories, and the full path of the selected files is included in the entries added into the zip archive. If you don't like these behaviors, see the other overloads of this method.

AddSelectedFiles ( String selectionCriteria, String directoryOnDisk ) : void

Adds to the ZipFile a set of files from a specified directory in the filesystem, that conform to the specified criteria.

This method selects files that conform to the specified criteria, from the the specified directory on disk, and adds them to the ZipFile. The search does not recurse into subdirectores.

Using this method, the full filesystem path of the files on disk is reproduced on the entries added to the zip file. If you don't want this behavior, use one of the other overloads of this method.

For details on the syntax for the selectionCriteria parameter, see .

AddSelectedFiles ( String selectionCriteria, String directoryOnDisk, String directoryPathInArchive ) : void

Adds to the ZipFile a selection of files from the specified directory on disk, that conform to the specified criteria, and using a specified root path for entries added to the zip archive.

This method selects files from the specified disk directory matching the specified selection criteria, and adds those files to the ZipFile, using the specified directory path in the archive. The search does not recurse into subdirectories. For details on the syntax for the selectionCriteria parameter, see AddSelectedFiles(String).

AddSelectedFiles ( String selectionCriteria, String directoryOnDisk, String directoryPathInArchive, bool recurseDirectories ) : void

Adds to the ZipFile a selection of files from the specified directory on disk, that conform to the specified criteria, optionally recursing through subdirectories, and using a specified root path for entries added to the zip archive.

This method selects files from the specified disk directory that match the specified selection criteria, and adds those files to the ZipFile, using the specified directory path in the archive. If recurseDirectories is true, files are also selected from subdirectories, and the directory structure in the filesystem is reproduced in the zip archive, rooted at the directory specified by directoryOnDisk. For details on the syntax for the selectionCriteria parameter, see .

AddSelectedFiles ( String selectionCriteria, String directoryOnDisk, bool recurseDirectories ) : void

Adds to the ZipFile a set of files from the specified directory on disk, that conform to the specified criteria.

This method selects files from the the specified disk directory matching the specified selection criteria, and adds them to the ZipFile. If recurseDirectories is true, files are also selected from subdirectories.

The full directory structure in the filesystem is reproduced on the entries added to the zip archive. If you don't want this behavior, use one of the overloads of this method that allows the specification of a directoryInArchive.

For details on the syntax for the selectionCriteria parameter, see .

AddSelectedFiles ( String selectionCriteria, bool recurseDirectories ) : void

Adds to the ZipFile a set of files from the disk that conform to the specified criteria, optionally recursing into subdirectories.

This method selects files from the the current working directory matching the specified criteria, and adds them to the ZipFile. If recurseDirectories is true, files are also selected from subdirectories, and the directory structure in the filesystem is reproduced in the zip archive, rooted at the current working directory.

Using this method, the full path of the selected files is included in the entries added into the zip archive. If you don't want this behavior, use one of the overloads of this method that allows the specification of a directoryInArchive.

For details on the syntax for the selectionCriteria parameter, see .

CheckZip ( string zipFileName ) : bool

Checks a zip file to see if its directory is consistent.

In cases of data error, the directory within a zip file can get out of synch with the entries in the zip file. This method checks the given zip file and returns true if this has occurred.

This method may take a long time to run for large zip files.

This method is not supported in the Reduced or Compact Framework versions of DotNetZip.

Developers using COM can use the ComHelper.CheckZip(String) method.

CheckZip ( string zipFileName, bool fixIfNecessary, TextWriter writer ) : bool

Checks a zip file to see if its directory is consistent, and optionally fixes the directory if necessary.

In cases of data error, the directory within a zip file can get out of synch with the entries in the zip file. This method checks the given zip file, and returns true if this has occurred. It also optionally fixes the zipfile, saving the fixed copy in Name_Fixed.zip.

This method may take a long time to run for large zip files. It will take even longer if the file actually needs to be fixed, and if fixIfNecessary is true.

This method is not supported in the Reduced or Compact Framework versions of DotNetZip.

CheckZipPassword ( string zipFileName, string password ) : bool

Verify the password on a zip file.

Keep in mind that passwords in zipfiles are applied to zip entries, not to the entire zip file. So testing a zipfile for a particular password doesn't work in the general case. On the other hand, it's often the case that a single password will be used on all entries in a zip file. This method works for that case.

There is no way to check a password without doing the decryption. So this code decrypts and extracts the given zipfile into System.IO.Stream.Null

ExtractAll ( string path ) : void

Extracts all of the items in the zip archive, to the specified path in the filesystem. The path can be relative or fully-qualified.

This method will extract all entries in the ZipFile to the specified path.

If an extraction of a file from the zip archive would overwrite an existing file in the filesystem, the action taken is dictated by the ExtractExistingFile property, which overrides any setting you may have made on individual ZipEntry instances. By default, if you have not set that property on the ZipFile instance, the entry will not be extracted, the existing file will not be overwritten and an exception will be thrown. To change this, set the property, or use the overload that allows you to specify an ExtractExistingFileAction parameter.

The action to take when an extract would overwrite an existing file applies to all entries. If you want to set this on a per-entry basis, then you must use one of the ZipEntry.Extract methods.

This method will send verbose output messages to the , if it is set on the ZipFile instance.

You may wish to take advantage of the ExtractProgress event.

About timestamps: When extracting a file entry from a zip archive, the extracted file gets the last modified time of the entry as stored in the archive. The archive may also store extended file timestamp information, including last accessed and created times. If these are present in the ZipEntry, then the extracted file will also get these times.

A Directory entry is somewhat different. It will get the times as described for a file entry, but, if there are file entries in the zip archive that, when extracted, appear in the just-created directory, then when those file entries are extracted, the last modified and last accessed times of the directory will change, as a side effect. The result is that after an extraction of a directory and a number of files within the directory, the last modified and last accessed timestamps on the directory will reflect the time that the last file was extracted into the directory, rather than the time stored in the zip archive for the directory.

To compensate, when extracting an archive with ExtractAll, DotNetZip will extract all the file and directory entries as described above, but it will then make a second pass on the directories, and reset the times on the directories to reflect what is stored in the zip archive.

This compensation is performed only within the context of an ExtractAll. If you call ZipEntry.Extract on a directory entry, the timestamps on directory in the filesystem will reflect the times stored in the zip. If you then call ZipEntry.Extract on a file entry, which is extracted into the directory, the timestamps on the directory will be updated to the current time.

ExtractAll ( string path, ExtractExistingFileAction extractExistingFile ) : void

Extracts all of the items in the zip archive, to the specified path in the filesystem, using the specified behavior when extraction would overwrite an existing file.

This method will extract all entries in the ZipFile to the specified path. For an extraction that would overwrite an existing file, the behavior is dictated by extractExistingFile, which overrides any setting you may have made on individual ZipEntry instances.

The action to take when an extract would overwrite an existing file applies to all entries. If you want to set this on a per-entry basis, then you must use or one of the similar methods.

Calling this method is equivalent to setting the property and then calling .

This method will send verbose output messages to the StatusMessageTextWriter, if it is set on the ZipFile instance.

ExtractSelectedEntries ( String selectionCriteria ) : void

Selects and Extracts a set of Entries from the ZipFile.

The entries are extracted into the current working directory.

If any of the files to be extracted already exist, then the action taken is as specified in the ZipEntry.ExtractExistingFile property on the corresponding ZipEntry instance. By default, the action taken in this case is to throw an exception.

For information on the syntax of the selectionCriteria string, see AddSelectedFiles(String).

ExtractSelectedEntries ( String selectionCriteria, ExtractExistingFileAction extractExistingFile ) : void

Selects and Extracts a set of Entries from the ZipFile.

The entries are extracted into the current working directory. When extraction would would overwrite an existing filesystem file, the action taken is as specified in the extractExistingFile parameter.

For information on the syntax of the string describing the entry selection criteria, see AddSelectedFiles(String).

ExtractSelectedEntries ( String selectionCriteria, String directoryPathInArchive ) : void

Selects and Extracts a set of Entries from the ZipFile.

The entries are selected from the specified directory within the archive, and then extracted into the current working directory.

If any of the files to be extracted already exist, then the action taken is as specified in the ZipEntry.ExtractExistingFile property on the corresponding ZipEntry instance. By default, the action taken in this case is to throw an exception.

For information on the syntax of the string describing the entry selection criteria, see AddSelectedFiles(String).

ExtractSelectedEntries ( String selectionCriteria, string directoryInArchive, string extractDirectory ) : void

Selects and Extracts a set of Entries from the ZipFile.

The entries are extracted into the specified directory. If any of the files to be extracted already exist, an exception will be thrown.

For information on the syntax of the string describing the entry selection criteria, see AddSelectedFiles(String).

ExtractSelectedEntries ( String selectionCriteria, string directoryPathInArchive, string extractDirectory, ExtractExistingFileAction extractExistingFile ) : void

Selects and Extracts a set of Entries from the ZipFile.

The entries are extracted into the specified directory. When extraction would would overwrite an existing filesystem file, the action taken is as specified in the extractExistingFile parameter.

For information on the syntax of the string describing the entry selection criteria, see AddSelectedFiles(String).

FixZipDirectory ( string zipFileName ) : void

Rewrite the directory within a zipfile.

In cases of data error, the directory in a zip file can get out of synch with the entries in the zip file. This method attempts to fix the zip file if this has occurred.

This can take a long time for large zip files.

This won't work if the zip file uses a non-standard code page - neither IBM437 nor UTF-8.

This method is not supported in the Reduced or Compact Framework versions of DotNetZip.

Developers using COM can use the ComHelper.FixZipDirectory(String) method.

GetEnumerator ( ) : System.Collections.Generic.IEnumerator

Generic IEnumerator support, for use of a ZipFile in an enumeration.

You probably do not want to call GetEnumerator explicitly. Instead it is implicitly called when you use a loop in C#, or a For Each loop in VB.NET.

IsZipFile ( Stream stream, bool testExtract ) : bool

Checks a stream to see if it contains a valid zip archive.

This method reads the zip archive contained in the specified stream, verifying the ZIP metadata as it reads. If testExtract is true, this method also extracts each entry in the archive, dumping all the bits into Stream.Null.

If everything succeeds, then the method returns true. If anything fails - for example if an incorrect signature or CRC is found, indicating a corrupt file, the the method returns false. This method also returns false for a file that does not exist.

If testExtract is true, this method reads in the content for each entry, expands it, and checks CRCs. This provides an additional check beyond verifying the zip header data.

If testExtract is true, and if any of the zip entries are protected with a password, this method will return false. If you want to verify a ZipFile that has entries which are protected with a password, you will need to do that manually.

IsZipFile ( string fileName ) : bool

Checks the given file to see if it appears to be a valid zip file.

Calling this method is equivalent to calling with the testExtract parameter set to false.

IsZipFile ( string fileName, bool testExtract ) : bool

Checks a file to see if it is a valid zip file.

This method opens the specified zip file, reads in the zip archive, verifying the ZIP metadata as it reads.

If everything succeeds, then the method returns true. If anything fails - for example if an incorrect signature or CRC is found, indicating a corrupt file, the the method returns false. This method also returns false for a file that does not exist.

If testExtract is true, as part of its check, this method reads in the content for each entry, expands it, and checks CRCs. This provides an additional check beyond verifying the zip header and directory data.

If testExtract is true, and if any of the zip entries are protected with a password, this method will return false. If you want to verify a ZipFile that has entries which are protected with a password, you will need to do that manually.

Read ( Stream zipStream ) : ZipFile

Reads a zip archive from a stream.

When reading from a file, it's probably easier to just use ZipFile.Read(String, ReadOptions). This overload is useful when when the zip archive content is available from an already-open stream. The stream must be open and readable and seekable when calling this method. The stream is left open when the reading is completed.

Using this overload, the stream is read using the default System.Text.Encoding, which is the IBM437 codepage. If you want to specify the encoding to use when reading the zipfile content, see ZipFile.Read(Stream, ReadOptions). This

Reading of zip content begins at the current position in the stream. This means if you have a stream that concatenates regular data and zip data, if you position the open, readable stream at the start of the zip data, you will be able to read the zip archive using this constructor, or any of the ZipFile constructors that accept a System.IO.Stream as input. Some examples of where this might be useful: the zip content is concatenated at the end of a regular EXE file, as some self-extracting archives do. (Note: SFX files produced by DotNetZip do not work this way; they can be read as normal ZIP files). Another example might be a stream being read from a database, where the zip content is embedded within an aggregate stream of data.

Read ( Stream zipStream, ReadOptions options ) : ZipFile

Reads a zip file archive from the given stream using the specified options.

When reading from a file, it's probably easier to just use ZipFile.Read(String, ReadOptions). This overload is useful when when the zip archive content is available from an already-open stream. The stream must be open and readable and seekable when calling this method. The stream is left open when the reading is completed.

Reading of zip content begins at the current position in the stream. This means if you have a stream that concatenates regular data and zip data, if you position the open, readable stream at the start of the zip data, you will be able to read the zip archive using this constructor, or any of the ZipFile constructors that accept a System.IO.Stream as input. Some examples of where this might be useful: the zip content is concatenated at the end of a regular EXE file, as some self-extracting archives do. (Note: SFX files produced by DotNetZip do not work this way; they can be read as normal ZIP files). Another example might be a stream being read from a database, where the zip content is embedded within an aggregate stream of data.

Read ( string fileName ) : ZipFile

Reads a zip file archive and returns the instance.

The stream is read using the default System.Text.Encoding, which is the IBM437 codepage.

Read ( string fileName, ReadOptions options ) : ZipFile

Reads a zip file archive from the named filesystem file using the specified options.

This version of the Read() method allows the caller to pass in a TextWriter an Encoding, via an instance of the ReadOptions class. The ZipFile is read in using the specified encoding for entries where UTF-8 encoding is not explicitly specified.

RemoveEntries ( System entriesToRemove ) : void

This method removes a collection of entries from the ZipFile, by name.

RemoveEntries ( System entriesToRemove ) : void

This method removes a collection of entries from the ZipFile.

RemoveSelectedEntries ( String selectionCriteria ) : int

Remove entries from the zipfile by specified criteria.

This method allows callers to remove the collection of entries from the zipfile that fit the specified criteria. The criteria are described in a string format, and can include patterns for the filename; constraints on the size of the entry; constraints on the last modified, created, or last accessed time for the file described by the entry; or the attributes of the entry.

For details on the syntax for the selectionCriteria parameter, see .

This method is intended for use with a ZipFile that has been read from storage. When creating a new ZipFile, this method will work only after the ZipArchive has been Saved to the disk (the ZipFile class subsequently and implicitly reads the Zip archive from storage.) Calling SelectEntries on a ZipFile that has not yet been saved will deliver undefined results.

RemoveSelectedEntries ( String selectionCriteria, string directoryPathInArchive ) : int

Remove entries from the zipfile by specified criteria, and within the specified path in the archive.

This method allows callers to remove the collection of entries from the zipfile that fit the specified criteria. The criteria are described in a string format, and can include patterns for the filename; constraints on the size of the entry; constraints on the last modified, created, or last accessed time for the file described by the entry; or the attributes of the entry.

For details on the syntax for the selectionCriteria parameter, see .

This method is intended for use with a ZipFile that has been read from storage. When creating a new ZipFile, this method will work only after the ZipArchive has been Saved to the disk (the ZipFile class subsequently and implicitly reads the Zip archive from storage.) Calling SelectEntries on a ZipFile that has not yet been saved will deliver undefined results.

Save ( ) : void

Saves the Zip archive to a file, specified by the Name property of the ZipFile.

The ZipFile instance is written to storage, typically a zip file in a filesystem, only when the caller calls Save. In the typical case, the Save operation writes the zip content to a temporary file, and then renames the temporary file to the desired name. If necessary, this method will delete a pre-existing file before the rename.

The ZipFile.Name property is specified either explicitly, or implicitly using one of the parameterized ZipFile constructors. For COM Automation clients, the Name property must be set explicitly, because COM Automation clients cannot call parameterized constructors.

When using a filesystem file for the Zip output, it is possible to call Save multiple times on the ZipFile instance. With each call the zip content is re-written to the same output file.

Data for entries that have been added to the ZipFile instance is written to the output when the Save method is called. This means that the input streams for those entries must be available at the time the application calls Save. If, for example, the application adds entries with AddEntry using a dynamically-allocated MemoryStream, the memory stream must not have been disposed before the call to Save. See the property for more discussion of the availability requirements of the input stream for an entry, and an approach for providing just-in-time stream lifecycle management.

Save ( Stream outputStream ) : void

Save the zip archive to the specified stream.

The ZipFile instance is written to storage - typically a zip file in a filesystem, but using this overload, the storage can be anything accessible via a writable stream - only when the caller calls Save.

Use this method to save the zip content to a stream directly. A common scenario is an ASP.NET application that dynamically generates a zip file and allows the browser to download it. The application can call Save(Response.OutputStream) to write a zipfile directly to the output stream, without creating a zip file on the disk on the ASP.NET server.

Be careful when saving a file to a non-seekable stream, including Response.OutputStream. When DotNetZip writes to a non-seekable stream, the zip archive is formatted in such a way that may not be compatible with all zip tools on all platforms. It's a perfectly legal and compliant zip file, but some people have reported problems opening files produced this way using the Mac OS archive utility.

Save ( String fileName ) : void

Save the file to a new zipfile, with the given name.

This method allows the application to explicitly specify the name of the zip file when saving. Use this when creating a new zip file, or when updating a zip archive.

An application can also save a zip archive in several places by calling this method multiple times in succession, with different filenames.

The ZipFile instance is written to storage, typically a zip file in a filesystem, only when the caller calls Save. The Save operation writes the zip content to a temporary file, and then renames the temporary file to the desired name. If necessary, this method will delete a pre-existing file before the rename.

SaveSelfExtractor ( string exeToGenerate, SelfExtractorFlavor flavor ) : void

Saves the ZipFile instance to a self-extracting zip archive.

The generated exe image will execute on any machine that has the .NET Framework 2.0 installed on it. The generated exe image is also a valid ZIP file, readable with DotNetZip or another Zip library or tool such as WinZip.

There are two "flavors" of self-extracting archive. The WinFormsApplication version will pop up a GUI and allow the user to select a target directory into which to extract. There's also a checkbox allowing the user to specify to overwrite existing files, and another checkbox to allow the user to request that Explorer be opened to see the extracted files after extraction. The other flavor is ConsoleApplication. A self-extractor generated with that flavor setting will run from the command line. It accepts command-line options to set the overwrite behavior, and to specify the target extraction directory.

There are a few temporary files created during the saving to a self-extracting zip. These files are created in the directory pointed to by ZipFile.TempFileFolder, which defaults to . These temporary files are removed upon successful completion of this method.

When a user runs the WinForms SFX, the user's personal directory (Environment.SpecialFolder.Personal) will be used as the default extract location. If you want to set the default extract location, you should use the other overload of SaveSelfExtractor()/ The user who runs the SFX will have the opportunity to change the extract directory before extracting. When the user runs the Command-Line SFX, the user must explicitly specify the directory to which to extract. The .NET Framework 2.0 is required on the computer when the self-extracting archive is run.

NB: This method is not available in the version of DotNetZip build for the .NET Compact Framework, nor in the "Reduced" DotNetZip library.

SaveSelfExtractor ( string exeToGenerate, SelfExtractorSaveOptions options ) : void

Saves the ZipFile instance to a self-extracting zip archive, using the specified save options.

This method saves a self extracting archive, using the specified save options. These options include the flavor of the SFX, the default extract directory, the icon file, and so on. See the documentation for SaveSelfExtractor(string , SelfExtractorFlavor) for more details.

The user who runs the SFX will have the opportunity to change the extract directory before extracting. If at the time of extraction, the specified directory does not exist, the SFX will create the directory before extracting the files.

SelectEntries ( String selectionCriteria ) : ICollection

Retrieve entries from the zipfile by specified criteria.

This method allows callers to retrieve the collection of entries from the zipfile that fit the specified criteria. The criteria are described in a string format, and can include patterns for the filename; constraints on the size of the entry; constraints on the last modified, created, or last accessed time for the file described by the entry; or the attributes of the entry.

For details on the syntax for the selectionCriteria parameter, see .

This method is intended for use with a ZipFile that has been read from storage. When creating a new ZipFile, this method will work only after the ZipArchive has been Saved to the disk (the ZipFile class subsequently and implicitly reads the Zip archive from storage.) Calling SelectEntries on a ZipFile that has not yet been saved will deliver undefined results.

SelectEntries ( String selectionCriteria, string directoryPathInArchive ) : ICollection

Retrieve entries from the zipfile by specified criteria.

This method allows callers to retrieve the collection of entries from the zipfile that fit the specified criteria. The criteria are described in a string format, and can include patterns for the filename; constraints on the size of the entry; constraints on the last modified, created, or last accessed time for the file described by the entry; or the attributes of the entry.

For details on the syntax for the selectionCriteria parameter, see .

This method is intended for use with a ZipFile that has been read from storage. When creating a new ZipFile, this method will work only after the ZipArchive has been Saved to the disk (the ZipFile class subsequently and implicitly reads the Zip archive from storage.) Calling SelectEntries on a ZipFile that has not yet been saved will deliver undefined results.

UpdateDirectory ( string directoryName ) : ZipEntry

Add or update a directory in a zip archive.

If the specified directory does not exist in the archive, then this method is equivalent to calling AddDirectory(). If the specified directory already exists in the archive, then this method updates any existing entries, and adds any new entries. Any entries that are in the zip archive but not in the specified directory, are left alone. In other words, the contents of the zip file will be a union of the previous contents and the new files.

UpdateDirectory ( string directoryName, String directoryPathInArchive ) : ZipEntry

Add or update a directory in the zip archive at the specified root directory in the archive.

If the specified directory does not exist in the archive, then this method is equivalent to calling AddDirectory(). If the specified directory already exists in the archive, then this method updates any existing entries, and adds any new entries. Any entries that are in the zip archive but not in the specified directory, are left alone. In other words, the contents of the zip file will be a union of the previous contents and the new files.

UpdateEntry ( string entryName, OpenDelegate opener, CloseDelegate closer ) : ZipEntry

Updates the given entry in the ZipFile, using the given delegates to open and close the stream that provides the content for the ZipEntry.

Calling this method is equivalent to removing the ZipEntry for the given file name and directory path, if it exists, and then calling . See the documentation for that method for further explanation.

UpdateEntry ( string entryName, Stream stream ) : ZipEntry

Updates the given entry in the ZipFile, using the given stream as input, and the given filename and given directory Path.

Calling the method is equivalent to calling RemoveEntry() if an entry by the same name already exists, and then calling AddEntry() with the given fileName and stream.

The stream must be open and readable during the call to ZipFile.Save. You can dispense the stream on a just-in-time basis using the ZipEntry.InputStream property. Check the documentation of that property for more information.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

UpdateEntry ( string entryName, WriteDelegate writer ) : ZipEntry

Updates the given entry in the ZipFile, using the given delegate as the source for content for the ZipEntry.

Calling this method is equivalent to removing the ZipEntry for the given file name and directory path, if it exists, and then calling . See the documentation for that method for further explanation.

UpdateEntry ( string entryName, byte byteContent ) : ZipEntry

Updates the given entry in the ZipFile, using the given byte array as content for the entry.

Calling this method is equivalent to removing the ZipEntry for the given filename and directory path, if it exists, and then calling AddEntry(String,byte[]). See the documentation for that method for further explanation.

UpdateEntry ( string entryName, string content ) : ZipEntry

Updates the given entry in the ZipFile, using the given string as content for the ZipEntry.

Calling this method is equivalent to removing the ZipEntry for the given file name and directory path, if it exists, and then calling AddEntry(String,String). See the documentation for that method for further explanation. The string content is encoded using the default encoding for the machine, or on Silverlight, using UTF-8. This encoding is distinct from the encoding used for the filename itself. See AlternateEncoding.

UpdateEntry ( string entryName, string content, System encoding ) : ZipEntry

Updates the given entry in the ZipFile, using the given string as content for the ZipEntry.

Calling this method is equivalent to removing the ZipEntry for the given file name and directory path, if it exists, and then calling . See the documentation for that method for further explanation.

UpdateFile ( string fileName ) : ZipEntry

Adds or Updates a File in a Zip file archive.

This method adds a file to a zip archive, or, if the file already exists in the zip archive, this method Updates the content of that given filename in the zip archive. The UpdateFile method might more accurately be called "AddOrUpdateFile".

Upon success, there is no way for the application to learn whether the file was added versus updated.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

UpdateFile ( string fileName, String directoryPathInArchive ) : ZipEntry

Adds or Updates a File in a Zip file archive.

This method adds a file to a zip archive, or, if the file already exists in the zip archive, this method Updates the content of that given filename in the zip archive.

This version of the method allows the caller to explicitly specify the directory path to be used in the archive. The entry to be added or updated is found by using the specified directory path, combined with the basename of the specified filename.

Upon success, there is no way for the application to learn if the file was added versus updated.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

UpdateFiles ( System fileNames ) : void

Adds or updates a set of files in the ZipFile.

Any files that already exist in the archive are updated. Any files that don't yet exist in the archive are added.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to each ZipEntry added.

UpdateFiles ( System fileNames, String directoryPathInArchive ) : void

Adds or updates a set of files to the ZipFile, using the specified directory path in the archive.

Any files that already exist in the archive are updated. Any files that don't yet exist in the archive are added.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to each ZipEntry added.

UpdateItem ( string itemName ) : void

Add or update a file or directory in the zip archive.

This is useful when the application is not sure or does not care if the item to be added is a file or directory, and does not know or does not care if the item already exists in the ZipFile. Calling this method is equivalent to calling RemoveEntry() if an entry by the same name already exists, followed calling by AddItem().

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

UpdateItem ( string itemName, string directoryPathInArchive ) : void

Add or update a file or directory.

This method is useful when the application is not sure or does not care if the item to be added is a file or directory, and does not know or does not care if the item already exists in the ZipFile. Calling this method is equivalent to calling RemoveEntry(), if an entry by that name exists, and then calling AddItem().

This version of the method allows the caller to explicitly specify the directory path to be used for the item being added to the archive. The entry or entries that are added or updated will use the specified DirectoryPathInArchive. Extracting the entry from the archive will result in a file stored in that directory path.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

UpdateSelectedFiles ( String selectionCriteria, String directoryOnDisk, String directoryPathInArchive, bool recurseDirectories ) : void

Updates the ZipFile with a selection of files from the disk that conform to the specified criteria.

This method selects files from the specified disk directory that match the specified selection criteria, and Updates the ZipFile with those files, using the specified directory path in the archive. If recurseDirectories is true, files are also selected from subdirectories, and the directory structure in the filesystem is reproduced in the zip archive, rooted at the directory specified by directoryOnDisk. For details on the syntax for the selectionCriteria parameter, see AddSelectedFiles(String).

Private Methods

Method Description
AddOrUpdateDirectoryImpl ( string directoryName, string rootDirectoryPathInArchive, AddOrUpdateAction action ) : ZipEntry
AddOrUpdateDirectoryImpl ( string directoryName, string rootDirectoryPathInArchive, AddOrUpdateAction action, bool recurse, int level ) : ZipEntry
AfterAddEntry ( ZipEntry entry ) : void
CleanupAfterSaveOperation ( ) : void
DeleteFileWithRetry ( string filename ) : void

Delete file with retry on UnauthorizedAccessException.

When calling File.Delete() on a file that has been "recently" created, the call sometimes fails with UnauthorizedAccessException. This method simply retries the Delete 3 times with a sleep between tries.

EnsureendInSlash ( string s ) : string
ExtractResourceToFile ( Assembly a, string resourceName, string filename ) : void
GenerateTempPathname ( string dir, string extension ) : string
GetNewEnum ( ) : System.Collections.IEnumerator
InternalAddEntry ( String name, ZipEntry entry ) : void
NotifyEntriesSaveComplete ( ICollection c ) : void
OnAddCompleted ( ) : void
OnAddStarted ( ) : void
OnExtractAllCompleted ( string path ) : void
OnExtractAllStarted ( string path ) : void
OnExtractBlock ( ZipEntry entry, System.Int64 bytesWritten, System.Int64 totalBytesToWrite ) : bool
OnExtractEntry ( int current, bool before, ZipEntry currentEntry, string path ) : void
OnExtractExisting ( ZipEntry entry, string path ) : bool
OnReadBytes ( ZipEntry entry ) : void
OnReadCompleted ( ) : void
OnReadEntry ( bool before, ZipEntry entry ) : void
OnReadStarted ( ) : void
OnSaveBlock ( ZipEntry entry, System.Int64 bytesXferred, System.Int64 totalBytesToXfer ) : bool
OnSaveCompleted ( ) : void
OnSaveEntry ( int current, ZipEntry entry, bool before ) : void
OnSaveEvent ( ZipProgressEventType eventFlavor ) : void
OnSaveStarted ( ) : void
OnSingleEntryExtract ( ZipEntry entry, string path, bool before ) : bool
OnZipErrorSaving ( ZipEntry entry, Exception exc ) : bool
Read ( Stream zipStream, TextWriter statusMessageWriter, System encoding, EventHandler readProgress ) : ZipFile

Reads a zip archive from a stream, using the specified text Encoding, the specified TextWriter for status messages, and the specified ReadProgress event handler.

Reading of zip content begins at the current position in the stream. This means if you have a stream that concatenates regular data and zip data, if you position the open, readable stream at the start of the zip data, you will be able to read the zip archive using this constructor, or any of the ZipFile constructors that accept a System.IO.Stream as input. Some examples of where this might be useful: the zip content is concatenated at the end of a regular EXE file, as some self-extracting archives do. (Note: SFX files produced by DotNetZip do not work this way). Another example might be a stream being read from a database, where the zip content is embedded within an aggregate stream of data.

Read ( string fileName, TextWriter statusMessageWriter, System encoding, EventHandler readProgress ) : ZipFile

Reads a zip file archive using the specified text encoding, the specified TextWriter for status messages, and the specified ReadProgress event handler, and returns the instance.

ReadCentralDirectory ( ZipFile zf ) : void
ReadCentralDirectoryFooter ( ZipFile zf ) : void
ReadFirstFourBytes ( Stream s ) : uint
ReadIntoInstance ( ZipFile zf ) : void
ReadIntoInstance_Orig ( ZipFile zf ) : void
ReadZipFileComment ( ZipFile zf ) : void
RemoveEntryForUpdate ( string entryName ) : void
RemoveTempFile ( ) : void
ReplaceEx ( string original, string pattern, string replacement ) : string
ReplaceLeadingDirectory ( string original, string pattern, string replacement ) : string
System ( ) : System.Collections.IEnumerator
Zip64SeekToCentralDirectory ( ZipFile zf ) : void
_AddOrUpdateSelectedFiles ( String selectionCriteria, String directoryOnDisk, String directoryPathInArchive, bool recurseDirectories, bool wantUpdate ) : void
_InternalAddEntry ( ZipEntry ze ) : ZipEntry
_InternalExtractAll ( string path, bool overrideExtractExistingProperty ) : void
_SaveSfxStub ( string exeToGenerate, SelfExtractorSaveOptions options ) : void

Method Details

AddDirectory() public method

Adds the contents of a filesystem directory to a Zip file archive.

The name of the directory may be a relative path or a fully-qualified path. Any files within the named directory are added to the archive. Any subdirectories within the named directory are also added to the archive, recursively.

Top-level entries in the named directory will appear as top-level entries in the zip archive. Entries in subdirectories in the named directory will result in entries in subdirectories in the zip archive.

If you want the entries to appear in a containing directory in the zip archive itself, then you should call the AddDirectory() overload that allows you to explicitly specify a directory path for use in the archive.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to each ZipEntry added.

public AddDirectory ( string directoryName ) : ZipEntry
directoryName string The name of the directory to add.
return ZipEntry

AddDirectory() public method

Adds the contents of a filesystem directory to a Zip file archive, overriding the path to be used for entries in the archive.

The name of the directory may be a relative path or a fully-qualified path. The add operation is recursive, so that any files or subdirectories within the name directory are also added to the archive.

Top-level entries in the named directory will appear as top-level entries in the zip archive. Entries in subdirectories in the named directory will result in entries in subdirectories in the zip archive.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to each ZipEntry added.

public AddDirectory ( string directoryName, string directoryPathInArchive ) : ZipEntry
directoryName string The name of the directory to add.
directoryPathInArchive string /// Specifies a directory path to use to override any path in the /// DirectoryName. This path may, or may not, correspond to a real directory /// in the current filesystem. If the zip is later extracted, this is the /// path used for the extracted file or directory. Passing null /// (Nothing in VB) or the empty string ("") will insert the items at /// the root path within the archive. ///
return ZipEntry

AddDirectoryByName() public method

Creates a directory in the zip archive.

Use this when you want to create a directory in the archive but there is no corresponding filesystem representation for that directory.

You will probably not need to do this in your code. One of the only times you will want to do this is if you want an empty directory in the zip archive. The reason: if you add a file to a zip archive that is stored within a multi-level directory, all of the directory tree is implicitly created in the zip archive.

public AddDirectoryByName ( string directoryNameInArchive ) : ZipEntry
directoryNameInArchive string /// The name of the directory to create in the archive. ///
return ZipEntry

AddEntry() public method

Add an entry, for which the application will provide a stream containing the entry data, on a just-in-time basis.

In cases where the application wishes to open the stream that holds the content for the ZipEntry, on a just-in-time basis, the application can use this method. The application provides an opener delegate that will be called by the DotNetZip library to obtain a readable stream that can be read to get the bytes for the given entry. Typically, this delegate opens a stream. Optionally, the application can provide a closer delegate as well, which will be called by DotNetZip when all bytes have been read from the entry.

These delegates are called from within the scope of the call to ZipFile.Save().

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

public AddEntry ( string entryName, OpenDelegate opener, CloseDelegate closer ) : ZipEntry
entryName string the name of the entry to add
opener OpenDelegate /// the delegate that will be invoked by ZipFile.Save() to get the /// readable stream for the given entry. ZipFile.Save() will call /// read on this stream to obtain the data for the entry. This data /// will then be compressed and written to the newly created zip /// file. ///
closer CloseDelegate /// the delegate that will be invoked to close the stream. This may /// be null (Nothing in VB), in which case no call is makde to close /// the stream. ///
return ZipEntry

AddEntry() public method

Create an entry in the ZipFile using the given Stream as input. The entry will have the given filename.

The application should provide an open, readable stream; in this case it will be read during the call to ZipFile.Save() or one of its overloads.

The passed stream will be read from its current position. If necessary, callers should set the position in the stream before calling AddEntry(). This might be appropriate when using this method with a MemoryStream, for example.

In cases where a large number of streams will be added to the ZipFile, the application may wish to avoid maintaining all of the streams open simultaneously. To handle this situation, the application should use the AddEntry(string, OpenDelegate, CloseDelegate) overload.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

public AddEntry ( string entryName, Stream stream ) : ZipEntry
entryName string /// The name, including any path, which is shown in the zip file for the added /// entry. ///
stream Stream /// The input stream from which to grab content for the file ///
return ZipEntry

AddEntry() public method

Add a ZipEntry for which content is written directly by the application.

When the application needs to write the zip entry data, use this method to add the ZipEntry. For example, in the case that the application wishes to write the XML representation of a DataSet into a ZipEntry, the application can use this method to do so.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

About progress events: When using the WriteDelegate, DotNetZip does not issue any SaveProgress events with EventType = Saving_EntryBytesRead. (This is because it is the application's code that runs in WriteDelegate - there's no way for DotNetZip to know when to issue a EntryBytesRead event.) Applications that want to update a progress bar or similar status indicator should do so from within the WriteDelegate itself. DotNetZip will issue the other SaveProgress events, including Saving_Started, Saving_BeforeWriteEntry, and Saving_AfterWriteEntry.

Note: When you use PKZip encryption, it's normally necessary to compute the CRC of the content to be encrypted, before compressing or encrypting it. Therefore, when using PKZip encryption with a WriteDelegate, the WriteDelegate CAN BE called twice: once to compute the CRC, and the second time to potentially compress and encrypt. Surprising, but true. This is because PKWARE specified that the encryption initialization data depends on the CRC. If this happens, for each call of the delegate, your application must stream the same entry data in its entirety. If your application writes different data during the second call, it will result in a corrupt zip file.

The double-read behavior happens with all types of entries, not only those that use WriteDelegate. It happens if you add an entry from a filesystem file, or using a string, or a stream, or an opener/closer pair. But in those cases, DotNetZip takes care of reading twice; in the case of the WriteDelegate, the application code gets invoked twice. Be aware.

As you can imagine, this can cause performance problems for large streams, and it can lead to correctness problems when you use a WriteDelegate. This is a pretty big pitfall. There are two ways to avoid it. First, and most preferred: don't use PKZIP encryption. If you use the WinZip AES encryption, this problem doesn't occur, because the encryption protocol doesn't require the CRC up front. Second: if you do choose to use PKZIP encryption, write out to a non-seekable stream (like standard output, or the Response.OutputStream in an ASP.NET application). In this case, DotNetZip will use an alternative encryption protocol that does not rely on the CRC of the content. This also implies setting bit 3 in the zip entry, which still presents problems for some zip tools.

In the future I may modify DotNetZip to *always* use bit 3 when PKZIP encryption is in use. This seems like a win overall, but there will be some work involved. If you feel strongly about it, visit the DotNetZip forums and vote up the Workitem tracking this issue.

public AddEntry ( string entryName, WriteDelegate writer ) : ZipEntry
entryName string the name of the entry to add
writer WriteDelegate the delegate which will write the entry content
return ZipEntry

AddEntry() public method

Add an entry into the zip archive using the given filename and directory path within the archive, and the given content for the file. No file is created in the filesystem.
public AddEntry ( string entryName, byte byteContent ) : ZipEntry
entryName string /// The name, including any path, to use within the archive for the entry. ///
byteContent byte The data to use for the entry.
return ZipEntry

AddEntry() public method

Adds a named entry into the zip archive, taking content for the entry from a string.
Calling this method creates an entry using the given fileName and directory path within the archive. There is no need for a file by the given name to exist in the filesystem; the name is used within the zip archive only. The content for the entry is encoded using the default text encoding for the machine, or on Silverlight, using UTF-8.
public AddEntry ( string entryName, string content ) : ZipEntry
entryName string /// The name, including any path, to use for the entry within the archive. ///
content string /// The content of the file, should it be extracted from the zip. ///
return ZipEntry

AddEntry() public method

Adds a named entry into the zip archive, taking content for the entry from a string, and using the specified text encoding.

Calling this method creates an entry using the given fileName and directory path within the archive. There is no need for a file by the given name to exist in the filesystem; the name is used within the zip archive only.

The content for the entry, a string value, is encoded using the given text encoding. A BOM (byte-order-mark) is emitted into the file, if the Encoding parameter is set for that.

Most Encoding classes support a constructor that accepts a boolean, indicating whether to emit a BOM or not. For example see .

public AddEntry ( string entryName, string content, System encoding ) : ZipEntry
entryName string /// The name, including any path, to use within the archive for the entry. ///
content string /// The content of the file, should it be extracted from the zip. ///
encoding System /// The text encoding to use when encoding the string. Be aware: This is /// distinct from the text encoding used to encode the fileName, as specified /// in . ///
return ZipEntry

AddFile() public method

Adds a File to a Zip file archive.

This call collects metadata for the named file in the filesystem, including the file attributes and the timestamp, and inserts that metadata into the resulting ZipEntry. Only when the application calls Save() on the ZipFile, does DotNetZip read the file from the filesystem and then write the content to the zip file archive.

This method will throw an exception if an entry with the same name already exists in the ZipFile.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

public AddFile ( string fileName ) : ZipEntry
fileName string /// The name of the file to add. It should refer to a file in the filesystem. /// The name of the file may be a relative path or a fully-qualified path. ///
return ZipEntry

AddFile() public method

Adds a File to a Zip file archive, potentially overriding the path to be used within the zip archive.

The file added by this call to the ZipFile is not written to the zip file archive until the application calls Save() on the ZipFile.

This method will throw an exception if an entry with the same name already exists in the ZipFile.

This version of the method allows the caller to explicitly specify the directory path to be used in the archive.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

public AddFile ( string fileName, String directoryPathInArchive ) : ZipEntry
fileName string /// The name of the file to add. The name of the file may be a relative path /// or a fully-qualified path. ///
directoryPathInArchive String /// Specifies a directory path to use to override any path in the fileName. /// This path may, or may not, correspond to a real directory in the current /// filesystem. If the files within the zip are later extracted, this is the /// path used for the extracted file. Passing null (Nothing in /// VB) will use the path on the fileName, if any. Passing the empty string /// ("") will insert the item at the root path within the archive. ///
return ZipEntry

AddFiles() public method

This method adds a set of files to the ZipFile.

Use this method to add a set of files to the zip archive, in one call. For example, a list of files received from System.IO.Directory.GetFiles() can be added to a zip archive in one call.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to each ZipEntry added.

public AddFiles ( System fileNames ) : void
fileNames System /// The collection of names of the files to add. Each string should refer to a /// file in the filesystem. The name of the file may be a relative path or a /// fully-qualified path. ///
return void

AddFiles() public method

Adds a set of files to the ZipFile, using the specified directory path in the archive.

Any directory structure that may be present in the filenames contained in the list is "flattened" in the archive. Each file in the list is added to the archive in the specified top-level directory.

For ZipFile properties including , Password, , , , , and , their respective values at the time of this call will be applied to each ZipEntry added.

public AddFiles ( System fileNames, String directoryPathInArchive ) : void
fileNames System /// The names of the files to add. Each string should refer to /// a file in the filesystem. The name of the file may be a /// relative path or a fully-qualified path. ///
directoryPathInArchive String /// Specifies a directory path to use to override any path in the file name. /// Th is path may, or may not, correspond to a real directory in the current /// filesystem. If the files within the zip are later extracted, this is the /// path used for the extracted file. Passing null (Nothing in /// VB) will use the path on each of the fileNames, if any. Passing /// the empty string ("") will insert the item at the root path within the /// archive. ///
return void

AddFiles() public method

Adds a set of files to the ZipFile, using the specified directory path in the archive, and preserving the full directory structure in the filenames.

Think of the directoryPathInArchive as a "root" or base directory used in the archive for the files that get added. when preserveDirHierarchy is true, the hierarchy of files found in the filesystem will be placed, with the hierarchy intact, starting at that root in the archive. When preserveDirHierarchy is false, the path hierarchy of files is flattned, and the flattened set of files gets placed in the root within the archive as specified in directoryPathInArchive.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to each ZipEntry added.

public AddFiles ( System fileNames, bool preserveDirHierarchy, String directoryPathInArchive ) : void
fileNames System /// The names of the files to add. Each string should refer to a file in the /// filesystem. The name of the file may be a relative path or a /// fully-qualified path. ///
preserveDirHierarchy bool /// whether the entries in the zip archive will reflect the directory /// hierarchy that is present in the various filenames. For example, if /// includes two paths, /// \Animalia\Chordata\Mammalia\Info.txt and /// \Plantae\Magnoliophyta\Dicotyledon\Info.txt, then calling this method /// with = false will /// result in an exception because of a duplicate entry name, while /// calling this method with = /// true will result in the full direcory paths being included in /// the entries added to the ZipFile. ///
directoryPathInArchive String /// Specifies a directory path to use as a prefix for each entry name. /// This path may, or may not, correspond to a real directory in the current /// filesystem. If the files within the zip are later extracted, this is the /// path used for the extracted file. Passing null (Nothing in /// VB) will use the path on each of the fileNames, if any. Passing /// the empty string ("") will insert the item at the root path within the /// archive. ///
return void

AddItem() public method

Adds an item, either a file or a directory, to a zip file archive, explicitly specifying the directory path to be used in the archive.

If adding a directory, the add is recursive on all files and subdirectories contained within it.

The name of the item may be a relative path or a fully-qualified path. The item added by this call to the ZipFile is not read from the disk nor written to the zip file archive until the application calls Save() on the ZipFile.

This version of the method allows the caller to explicitly specify the directory path to be used in the archive, which would override the "natural" path of the filesystem file.

Encryption will be used on the file data if the Password has been set on the ZipFile object, prior to calling this method.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

/// Thrown if the file or directory passed in does not exist. ///
public AddItem ( String fileOrDirectoryName, String directoryPathInArchive ) : ZipEntry
fileOrDirectoryName String the name of the file or directory to add. ///
directoryPathInArchive String /// The name of the directory path to use within the zip archive. This path /// need not refer to an extant directory in the current filesystem. If the /// files within the zip are later extracted, this is the path used for the /// extracted file. Passing null (Nothing in VB) will use the /// path on the fileOrDirectoryName. Passing the empty string ("") will /// insert the item at the root path within the archive. ///
return ZipEntry

AddItem() public method

Adds an item, either a file or a directory, to a zip file archive.

This method is handy if you are adding things to zip archive and don't want to bother distinguishing between directories or files. Any files are added as single entries. A directory added through this method is added recursively: all files and subdirectories contained within the directory are added to the ZipFile.

The name of the item may be a relative path or a fully-qualified path. Remember, the items contained in ZipFile instance get written to the disk only when you call ZipFile.Save() or a similar save method.

The directory name used for the file within the archive is the same as the directory name (potentially a relative path) specified in the fileOrDirectoryName.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

public AddItem ( string fileOrDirectoryName ) : ZipEntry
fileOrDirectoryName string /// the name of the file or directory to add.
return ZipEntry

AddSelectedFiles() public method

Adds to the ZipFile a set of files from the current working directory on disk, that conform to the specified criteria.

This method selects files from the the current working directory matching the specified criteria, and adds them to the ZipFile.

Specify the criteria in statements of 3 elements: a noun, an operator, and a value. Consider the string "name != *.doc" . The noun is "name". The operator is "!=", implying "Not Equal". The value is "*.doc". That criterion, in English, says "all files with a name that does not end in the .doc extension."

Supported nouns include "name" (or "filename") for the filename; "atime", "mtime", and "ctime" for last access time, last modfied time, and created time of the file, respectively; "attributes" (or "attrs") for the file attributes; "size" (or "length") for the file length (uncompressed), and "type" for the type of object, either a file or a directory. The "attributes", "name" and "type" nouns both support = and != as operators. The "size", "atime", "mtime", and "ctime" nouns support = and !=, and >, >=, <, <= as well. The times are taken to be expressed in local time.

Specify values for the file attributes as a string with one or more of the characters H,R,S,A,I,L in any order, implying file attributes of Hidden, ReadOnly, System, Archive, NotContextIndexed, and ReparsePoint (symbolic link) respectively.

To specify a time, use YYYY-MM-DD-HH:mm:ss or YYYY/MM/DD-HH:mm:ss as the format. If you omit the HH:mm:ss portion, it is assumed to be 00:00:00 (midnight).

The value for a size criterion is expressed in integer quantities of bytes, kilobytes (use k or kb after the number), megabytes (m or mb), or gigabytes (g or gb).

The value for a name is a pattern to match against the filename, potentially including wildcards. The pattern follows CMD.exe glob rules: * implies one or more of any character, while ? implies one character. If the name pattern contains any slashes, it is matched to the entire filename, including the path; otherwise, it is matched against only the filename without the path. This means a pattern of "*\*.*" matches all files one directory level deep, while a pattern of "*.*" matches all files in all directories.

To specify a name pattern that includes spaces, use single quotes around the pattern. A pattern of "'* *.*'" will match all files that have spaces in the filename. The full criteria string for that would be "name = '* *.*'" .

The value for a type criterion is either F (implying a file) or D (implying a directory).

Some examples:

criteria Files retrieved name != *.xls any file with an extension that is not .xls name = *.mp3 any file with a .mp3 extension. *.mp3 (same as above) any file with a .mp3 extension. attributes = A all files whose attributes include the Archive bit. attributes != H all files whose attributes do not include the Hidden bit. mtime > 2009-01-01 all files with a last modified time after January 1st, 2009. size > 2gb all files whose uncompressed size is greater than 2gb. type = D all directories in the filesystem.

You can combine criteria with the conjunctions AND or OR. Using a string like "name = *.txt AND size >= 100k" for the selectionCriteria retrieves entries whose names end in .txt, and whose uncompressed size is greater than or equal to 100 kilobytes.

For more complex combinations of criteria, you can use parenthesis to group clauses in the boolean logic. Without parenthesis, the precedence of the criterion atoms is determined by order of appearance. Unlike the C# language, the AND conjunction does not take precendence over the logical OR. This is important only in strings that contain 3 or more criterion atoms. In other words, "name = *.txt and size > 1000 or attributes = H" implies "((name = *.txt AND size > 1000) OR attributes = H)" while "attributes = H OR name = *.txt and size > 1000" evaluates to "((attributes = H OR name = *.txt) AND size > 1000)". When in doubt, use parenthesis.

Using time properties requires some extra care. If you want to retrieve all entries that were last updated on 2009 February 14, specify a time range like so:"mtime >= 2009-02-14 AND mtime < 2009-02-15". Read this to say: all files updated after 12:00am on February 14th, until 12:00am on February 15th. You can use the same bracketing approach to specify any time period - a year, a month, a week, and so on.

The syntax allows one special case: if you provide a string with no spaces, it is treated as a pattern to match for the filename. Therefore a string like "*.xls" will be equivalent to specifying "name = *.xls".

There is no logic in this method that insures that the file inclusion criteria are internally consistent. For example, it's possible to specify criteria that says the file must have a size of less than 100 bytes, as well as a size that is greater than 1000 bytes. Obviously no file will ever satisfy such criteria, but this method does not detect such logical inconsistencies. The caller is responsible for insuring the criteria are sensible.

Using this method, the file selection does not recurse into subdirectories, and the full path of the selected files is included in the entries added into the zip archive. If you don't like these behaviors, see the other overloads of this method.

public AddSelectedFiles ( String selectionCriteria ) : void
selectionCriteria String The criteria for file selection
return void

AddSelectedFiles() public method

Adds to the ZipFile a set of files from a specified directory in the filesystem, that conform to the specified criteria.

This method selects files that conform to the specified criteria, from the the specified directory on disk, and adds them to the ZipFile. The search does not recurse into subdirectores.

Using this method, the full filesystem path of the files on disk is reproduced on the entries added to the zip file. If you don't want this behavior, use one of the other overloads of this method.

For details on the syntax for the selectionCriteria parameter, see .

public AddSelectedFiles ( String selectionCriteria, String directoryOnDisk ) : void
selectionCriteria String The criteria for file selection
directoryOnDisk String /// The name of the directory on the disk from which to select files. ///
return void

AddSelectedFiles() public method

Adds to the ZipFile a selection of files from the specified directory on disk, that conform to the specified criteria, and using a specified root path for entries added to the zip archive.

This method selects files from the specified disk directory matching the specified selection criteria, and adds those files to the ZipFile, using the specified directory path in the archive. The search does not recurse into subdirectories. For details on the syntax for the selectionCriteria parameter, see AddSelectedFiles(String).

public AddSelectedFiles ( String selectionCriteria, String directoryOnDisk, String directoryPathInArchive ) : void
selectionCriteria String /// The criteria for selection of files to add to the ZipFile. ///
directoryOnDisk String /// The path to the directory in the filesystem from which to select files. ///
directoryPathInArchive String /// Specifies a directory path to use to in place of the /// directoryOnDisk. This path may, or may not, correspond to a real /// directory in the current filesystem. If the files within the zip are /// later extracted, this is the path used for the extracted file. Passing /// null (nothing in VB) will use the path on the file name, if any; in other /// words it would use directoryOnDisk, plus any subdirectory. Passing /// the empty string ("") will insert the item at the root path within the /// archive. ///
return void

AddSelectedFiles() public method

Adds to the ZipFile a selection of files from the specified directory on disk, that conform to the specified criteria, optionally recursing through subdirectories, and using a specified root path for entries added to the zip archive.
This method selects files from the specified disk directory that match the specified selection criteria, and adds those files to the ZipFile, using the specified directory path in the archive. If recurseDirectories is true, files are also selected from subdirectories, and the directory structure in the filesystem is reproduced in the zip archive, rooted at the directory specified by directoryOnDisk. For details on the syntax for the selectionCriteria parameter, see .
public AddSelectedFiles ( String selectionCriteria, String directoryOnDisk, String directoryPathInArchive, bool recurseDirectories ) : void
selectionCriteria String /// The criteria for selection of files to add to the ZipFile. ///
directoryOnDisk String /// The path to the directory in the filesystem from which to select files. ///
directoryPathInArchive String /// Specifies a directory path to use to in place of the /// directoryOnDisk. This path may, or may not, correspond to a real /// directory in the current filesystem. If the files within the zip are /// later extracted, this is the path used for the extracted file. Passing /// null (nothing in VB) will use the path on the file name, if any; in other /// words it would use directoryOnDisk, plus any subdirectory. Passing /// the empty string ("") will insert the item at the root path within the /// archive. ///
recurseDirectories bool /// If true, the method also scans subdirectories for files matching the /// criteria. ///
return void

AddSelectedFiles() public method

Adds to the ZipFile a set of files from the specified directory on disk, that conform to the specified criteria.

This method selects files from the the specified disk directory matching the specified selection criteria, and adds them to the ZipFile. If recurseDirectories is true, files are also selected from subdirectories.

The full directory structure in the filesystem is reproduced on the entries added to the zip archive. If you don't want this behavior, use one of the overloads of this method that allows the specification of a directoryInArchive.

For details on the syntax for the selectionCriteria parameter, see .

public AddSelectedFiles ( String selectionCriteria, String directoryOnDisk, bool recurseDirectories ) : void
selectionCriteria String The criteria for file selection
directoryOnDisk String /// The filesystem path from which to select files. ///
recurseDirectories bool /// If true, the file selection will recurse into subdirectories. ///
return void

AddSelectedFiles() public method

Adds to the ZipFile a set of files from the disk that conform to the specified criteria, optionally recursing into subdirectories.

This method selects files from the the current working directory matching the specified criteria, and adds them to the ZipFile. If recurseDirectories is true, files are also selected from subdirectories, and the directory structure in the filesystem is reproduced in the zip archive, rooted at the current working directory.

Using this method, the full path of the selected files is included in the entries added into the zip archive. If you don't want this behavior, use one of the overloads of this method that allows the specification of a directoryInArchive.

For details on the syntax for the selectionCriteria parameter, see .

public AddSelectedFiles ( String selectionCriteria, bool recurseDirectories ) : void
selectionCriteria String The criteria for file selection
recurseDirectories bool /// If true, the file selection will recurse into subdirectories. ///
return void

CheckZip() public static method

Checks a zip file to see if its directory is consistent.

In cases of data error, the directory within a zip file can get out of synch with the entries in the zip file. This method checks the given zip file and returns true if this has occurred.

This method may take a long time to run for large zip files.

This method is not supported in the Reduced or Compact Framework versions of DotNetZip.

Developers using COM can use the ComHelper.CheckZip(String) method.

public static CheckZip ( string zipFileName ) : bool
zipFileName string The filename to of the zip file to check.
return bool

CheckZip() public static method

Checks a zip file to see if its directory is consistent, and optionally fixes the directory if necessary.

In cases of data error, the directory within a zip file can get out of synch with the entries in the zip file. This method checks the given zip file, and returns true if this has occurred. It also optionally fixes the zipfile, saving the fixed copy in Name_Fixed.zip.

This method may take a long time to run for large zip files. It will take even longer if the file actually needs to be fixed, and if fixIfNecessary is true.

This method is not supported in the Reduced or Compact Framework versions of DotNetZip.

public static CheckZip ( string zipFileName, bool fixIfNecessary, TextWriter writer ) : bool
zipFileName string The filename to of the zip file to check.
fixIfNecessary bool If true, the method will fix the zip file if /// necessary.
writer System.IO.TextWriter /// a TextWriter in which messages generated while checking will be written. ///
return bool

CheckZipPassword() public static method

Verify the password on a zip file.

Keep in mind that passwords in zipfiles are applied to zip entries, not to the entire zip file. So testing a zipfile for a particular password doesn't work in the general case. On the other hand, it's often the case that a single password will be used on all entries in a zip file. This method works for that case.

There is no way to check a password without doing the decryption. So this code decrypts and extracts the given zipfile into System.IO.Stream.Null

public static CheckZipPassword ( string zipFileName, string password ) : bool
zipFileName string The filename to of the zip file to fix.
password string The password to check.
return bool

ExtractAll() public method

Extracts all of the items in the zip archive, to the specified path in the filesystem. The path can be relative or fully-qualified.

This method will extract all entries in the ZipFile to the specified path.

If an extraction of a file from the zip archive would overwrite an existing file in the filesystem, the action taken is dictated by the ExtractExistingFile property, which overrides any setting you may have made on individual ZipEntry instances. By default, if you have not set that property on the ZipFile instance, the entry will not be extracted, the existing file will not be overwritten and an exception will be thrown. To change this, set the property, or use the overload that allows you to specify an ExtractExistingFileAction parameter.

The action to take when an extract would overwrite an existing file applies to all entries. If you want to set this on a per-entry basis, then you must use one of the ZipEntry.Extract methods.

This method will send verbose output messages to the , if it is set on the ZipFile instance.

You may wish to take advantage of the ExtractProgress event.

About timestamps: When extracting a file entry from a zip archive, the extracted file gets the last modified time of the entry as stored in the archive. The archive may also store extended file timestamp information, including last accessed and created times. If these are present in the ZipEntry, then the extracted file will also get these times.

A Directory entry is somewhat different. It will get the times as described for a file entry, but, if there are file entries in the zip archive that, when extracted, appear in the just-created directory, then when those file entries are extracted, the last modified and last accessed times of the directory will change, as a side effect. The result is that after an extraction of a directory and a number of files within the directory, the last modified and last accessed timestamps on the directory will reflect the time that the last file was extracted into the directory, rather than the time stored in the zip archive for the directory.

To compensate, when extracting an archive with ExtractAll, DotNetZip will extract all the file and directory entries as described above, but it will then make a second pass on the directories, and reset the times on the directories to reflect what is stored in the zip archive.

This compensation is performed only within the context of an ExtractAll. If you call ZipEntry.Extract on a directory entry, the timestamps on directory in the filesystem will reflect the times stored in the zip. If you then call ZipEntry.Extract on a file entry, which is extracted into the directory, the timestamps on the directory will be updated to the current time.

public ExtractAll ( string path ) : void
path string /// The path to which the contents of the zipfile will be extracted. /// The path can be relative or fully-qualified. ///
return void

ExtractAll() public method

Extracts all of the items in the zip archive, to the specified path in the filesystem, using the specified behavior when extraction would overwrite an existing file.

This method will extract all entries in the ZipFile to the specified path. For an extraction that would overwrite an existing file, the behavior is dictated by extractExistingFile, which overrides any setting you may have made on individual ZipEntry instances.

The action to take when an extract would overwrite an existing file applies to all entries. If you want to set this on a per-entry basis, then you must use or one of the similar methods.

Calling this method is equivalent to setting the property and then calling .

This method will send verbose output messages to the StatusMessageTextWriter, if it is set on the ZipFile instance.

public ExtractAll ( string path, ExtractExistingFileAction extractExistingFile ) : void
path string /// The path to which the contents of the zipfile will be extracted. /// The path can be relative or fully-qualified. ///
extractExistingFile ExtractExistingFileAction /// The action to take if extraction would overwrite an existing file. ///
return void

ExtractSelectedEntries() public method

Selects and Extracts a set of Entries from the ZipFile.

The entries are extracted into the current working directory.

If any of the files to be extracted already exist, then the action taken is as specified in the ZipEntry.ExtractExistingFile property on the corresponding ZipEntry instance. By default, the action taken in this case is to throw an exception.

For information on the syntax of the selectionCriteria string, see AddSelectedFiles(String).

public ExtractSelectedEntries ( String selectionCriteria ) : void
selectionCriteria String the selection criteria for entries to extract.
return void

ExtractSelectedEntries() public method

Selects and Extracts a set of Entries from the ZipFile.

The entries are extracted into the current working directory. When extraction would would overwrite an existing filesystem file, the action taken is as specified in the extractExistingFile parameter.

For information on the syntax of the string describing the entry selection criteria, see AddSelectedFiles(String).

public ExtractSelectedEntries ( String selectionCriteria, ExtractExistingFileAction extractExistingFile ) : void
selectionCriteria String the selection criteria for entries to extract.
extractExistingFile ExtractExistingFileAction /// The action to take if extraction would overwrite an existing file. ///
return void

ExtractSelectedEntries() public method

Selects and Extracts a set of Entries from the ZipFile.

The entries are selected from the specified directory within the archive, and then extracted into the current working directory.

If any of the files to be extracted already exist, then the action taken is as specified in the ZipEntry.ExtractExistingFile property on the corresponding ZipEntry instance. By default, the action taken in this case is to throw an exception.

For information on the syntax of the string describing the entry selection criteria, see AddSelectedFiles(String).

public ExtractSelectedEntries ( String selectionCriteria, String directoryPathInArchive ) : void
selectionCriteria String the selection criteria for entries to extract.
directoryPathInArchive String /// the directory in the archive from which to select entries. If null, then /// all directories in the archive are used. ///
return void

ExtractSelectedEntries() public method

Selects and Extracts a set of Entries from the ZipFile.

The entries are extracted into the specified directory. If any of the files to be extracted already exist, an exception will be thrown.

For information on the syntax of the string describing the entry selection criteria, see AddSelectedFiles(String).

public ExtractSelectedEntries ( String selectionCriteria, string directoryInArchive, string extractDirectory ) : void
selectionCriteria String the selection criteria for entries to extract.
directoryInArchive string /// the directory in the archive from which to select entries. If null, then /// all directories in the archive are used. ///
extractDirectory string /// the directory on the disk into which to extract. It will be created /// if it does not exist. ///
return void

ExtractSelectedEntries() public method

Selects and Extracts a set of Entries from the ZipFile.

The entries are extracted into the specified directory. When extraction would would overwrite an existing filesystem file, the action taken is as specified in the extractExistingFile parameter.

For information on the syntax of the string describing the entry selection criteria, see AddSelectedFiles(String).

public ExtractSelectedEntries ( String selectionCriteria, string directoryPathInArchive, string extractDirectory, ExtractExistingFileAction extractExistingFile ) : void
selectionCriteria String the selection criteria for entries to extract.
directoryPathInArchive string /// The directory in the archive from which to select entries. If null, then /// all directories in the archive are used. ///
extractDirectory string /// The directory on the disk into which to extract. It will be created if it does not exist. ///
extractExistingFile ExtractExistingFileAction /// The action to take if extraction would overwrite an existing file. ///
return void

FixZipDirectory() public static method

Rewrite the directory within a zipfile.

In cases of data error, the directory in a zip file can get out of synch with the entries in the zip file. This method attempts to fix the zip file if this has occurred.

This can take a long time for large zip files.

This won't work if the zip file uses a non-standard code page - neither IBM437 nor UTF-8.

This method is not supported in the Reduced or Compact Framework versions of DotNetZip.

Developers using COM can use the ComHelper.FixZipDirectory(String) method.

public static FixZipDirectory ( string zipFileName ) : void
zipFileName string The filename to of the zip file to fix.
return void

GetEnumerator() public method

Generic IEnumerator support, for use of a ZipFile in an enumeration.
You probably do not want to call GetEnumerator explicitly. Instead it is implicitly called when you use a loop in C#, or a For Each loop in VB.NET.
public GetEnumerator ( ) : System.Collections.Generic.IEnumerator
return System.Collections.Generic.IEnumerator

IsZipFile() public static method

Checks a stream to see if it contains a valid zip archive.

This method reads the zip archive contained in the specified stream, verifying the ZIP metadata as it reads. If testExtract is true, this method also extracts each entry in the archive, dumping all the bits into Stream.Null.

If everything succeeds, then the method returns true. If anything fails - for example if an incorrect signature or CRC is found, indicating a corrupt file, the the method returns false. This method also returns false for a file that does not exist.

If testExtract is true, this method reads in the content for each entry, expands it, and checks CRCs. This provides an additional check beyond verifying the zip header data.

If testExtract is true, and if any of the zip entries are protected with a password, this method will return false. If you want to verify a ZipFile that has entries which are protected with a password, you will need to do that manually.

public static IsZipFile ( Stream stream, bool testExtract ) : bool
stream Stream The stream to check.
testExtract bool true if the caller wants to extract each entry.
return bool

IsZipFile() public static method

Checks the given file to see if it appears to be a valid zip file.

Calling this method is equivalent to calling with the testExtract parameter set to false.

public static IsZipFile ( string fileName ) : bool
fileName string The file to check.
return bool

IsZipFile() public static method

Checks a file to see if it is a valid zip file.

This method opens the specified zip file, reads in the zip archive, verifying the ZIP metadata as it reads.

If everything succeeds, then the method returns true. If anything fails - for example if an incorrect signature or CRC is found, indicating a corrupt file, the the method returns false. This method also returns false for a file that does not exist.

If testExtract is true, as part of its check, this method reads in the content for each entry, expands it, and checks CRCs. This provides an additional check beyond verifying the zip header and directory data.

If testExtract is true, and if any of the zip entries are protected with a password, this method will return false. If you want to verify a ZipFile that has entries which are protected with a password, you will need to do that manually.

public static IsZipFile ( string fileName, bool testExtract ) : bool
fileName string The zip file to check.
testExtract bool true if the caller wants to extract each entry.
return bool

Read() public static method

Reads a zip archive from a stream.

When reading from a file, it's probably easier to just use ZipFile.Read(String, ReadOptions). This overload is useful when when the zip archive content is available from an already-open stream. The stream must be open and readable and seekable when calling this method. The stream is left open when the reading is completed.

Using this overload, the stream is read using the default System.Text.Encoding, which is the IBM437 codepage. If you want to specify the encoding to use when reading the zipfile content, see ZipFile.Read(Stream, ReadOptions). This

Reading of zip content begins at the current position in the stream. This means if you have a stream that concatenates regular data and zip data, if you position the open, readable stream at the start of the zip data, you will be able to read the zip archive using this constructor, or any of the ZipFile constructors that accept a System.IO.Stream as input. Some examples of where this might be useful: the zip content is concatenated at the end of a regular EXE file, as some self-extracting archives do. (Note: SFX files produced by DotNetZip do not work this way; they can be read as normal ZIP files). Another example might be a stream being read from a database, where the zip content is embedded within an aggregate stream of data.

public static Read ( Stream zipStream ) : ZipFile
zipStream Stream the stream containing the zip data.
return ZipFile

Read() public static method

Reads a zip file archive from the given stream using the specified options.

When reading from a file, it's probably easier to just use ZipFile.Read(String, ReadOptions). This overload is useful when when the zip archive content is available from an already-open stream. The stream must be open and readable and seekable when calling this method. The stream is left open when the reading is completed.

Reading of zip content begins at the current position in the stream. This means if you have a stream that concatenates regular data and zip data, if you position the open, readable stream at the start of the zip data, you will be able to read the zip archive using this constructor, or any of the ZipFile constructors that accept a System.IO.Stream as input. Some examples of where this might be useful: the zip content is concatenated at the end of a regular EXE file, as some self-extracting archives do. (Note: SFX files produced by DotNetZip do not work this way; they can be read as normal ZIP files). Another example might be a stream being read from a database, where the zip content is embedded within an aggregate stream of data.

/// Thrown if the zip archive cannot be read. ///
public static Read ( Stream zipStream, ReadOptions options ) : ZipFile
zipStream Stream the stream containing the zip data.
options ReadOptions /// The set of options to use when reading the zip file. ///
return ZipFile

Read() public static method

Reads a zip file archive and returns the instance.

The stream is read using the default System.Text.Encoding, which is the IBM437 codepage.

/// Thrown if the ZipFile cannot be read. The implementation of this method /// relies on System.IO.File.OpenRead, which can throw a variety of exceptions, /// including specific exceptions if a file is not found, an unauthorized access /// exception, exceptions for poorly formatted filenames, and so on. ///
public static Read ( string fileName ) : ZipFile
fileName string /// The name of the zip archive to open. This can be a fully-qualified or relative /// pathname. ///
return ZipFile

Read() public static method

Reads a zip file archive from the named filesystem file using the specified options.

This version of the Read() method allows the caller to pass in a TextWriter an Encoding, via an instance of the ReadOptions class. The ZipFile is read in using the specified encoding for entries where UTF-8 encoding is not explicitly specified.

/// Thrown if the zipfile cannot be read. The implementation of /// this method relies on System.IO.File.OpenRead, which /// can throw a variety of exceptions, including specific /// exceptions if a file is not found, an unauthorized access /// exception, exceptions for poorly formatted filenames, and so /// on. ///
public static Read ( string fileName, ReadOptions options ) : ZipFile
fileName string /// The name of the zip archive to open. /// This can be a fully-qualified or relative pathname. ///
options ReadOptions /// The set of options to use when reading the zip file. ///
return ZipFile

RemoveEntries() public method

This method removes a collection of entries from the ZipFile, by name.
public RemoveEntries ( System entriesToRemove ) : void
entriesToRemove System /// A collection of strings that refer to names of entries to be removed /// from the ZipFile. For example, you can pass in an array or a /// List of Strings that provide the names of entries to be removed. ///
return void

RemoveEntries() public method

This method removes a collection of entries from the ZipFile.
public RemoveEntries ( System entriesToRemove ) : void
entriesToRemove System /// A collection of ZipEntry instances from this zip file to be removed. For /// example, you can pass in an array of ZipEntry instances; or you can call /// SelectEntries(), and then add or remove entries from that /// ICollection<ZipEntry> (ICollection(Of ZipEntry) in VB), and pass /// that ICollection to this method. ///
return void

RemoveSelectedEntries() public method

Remove entries from the zipfile by specified criteria.

This method allows callers to remove the collection of entries from the zipfile that fit the specified criteria. The criteria are described in a string format, and can include patterns for the filename; constraints on the size of the entry; constraints on the last modified, created, or last accessed time for the file described by the entry; or the attributes of the entry.

For details on the syntax for the selectionCriteria parameter, see .

This method is intended for use with a ZipFile that has been read from storage. When creating a new ZipFile, this method will work only after the ZipArchive has been Saved to the disk (the ZipFile class subsequently and implicitly reads the Zip archive from storage.) Calling SelectEntries on a ZipFile that has not yet been saved will deliver undefined results.

/// Thrown if selectionCriteria has an invalid syntax. ///
public RemoveSelectedEntries ( String selectionCriteria ) : int
selectionCriteria String the string that specifies which entries to select
return int

RemoveSelectedEntries() public method

Remove entries from the zipfile by specified criteria, and within the specified path in the archive.

This method allows callers to remove the collection of entries from the zipfile that fit the specified criteria. The criteria are described in a string format, and can include patterns for the filename; constraints on the size of the entry; constraints on the last modified, created, or last accessed time for the file described by the entry; or the attributes of the entry.

For details on the syntax for the selectionCriteria parameter, see .

This method is intended for use with a ZipFile that has been read from storage. When creating a new ZipFile, this method will work only after the ZipArchive has been Saved to the disk (the ZipFile class subsequently and implicitly reads the Zip archive from storage.) Calling SelectEntries on a ZipFile that has not yet been saved will deliver undefined results.

/// Thrown if selectionCriteria has an invalid syntax. ///
public RemoveSelectedEntries ( String selectionCriteria, string directoryPathInArchive ) : int
selectionCriteria String the string that specifies which entries to select
directoryPathInArchive string /// the directory in the archive from which to select entries. If null, then /// all directories in the archive are used. ///
return int

Save() public method

Saves the Zip archive to a file, specified by the Name property of the ZipFile.

The ZipFile instance is written to storage, typically a zip file in a filesystem, only when the caller calls Save. In the typical case, the Save operation writes the zip content to a temporary file, and then renames the temporary file to the desired name. If necessary, this method will delete a pre-existing file before the rename.

The ZipFile.Name property is specified either explicitly, or implicitly using one of the parameterized ZipFile constructors. For COM Automation clients, the Name property must be set explicitly, because COM Automation clients cannot call parameterized constructors.

When using a filesystem file for the Zip output, it is possible to call Save multiple times on the ZipFile instance. With each call the zip content is re-written to the same output file.

Data for entries that have been added to the ZipFile instance is written to the output when the Save method is called. This means that the input streams for those entries must be available at the time the application calls Save. If, for example, the application adds entries with AddEntry using a dynamically-allocated MemoryStream, the memory stream must not have been disposed before the call to Save. See the property for more discussion of the availability requirements of the input stream for an entry, and an approach for providing just-in-time stream lifecycle management.

/// Thrown if you haven't specified a location or stream for saving the zip, /// either in the constructor or by setting the Name property, or if you try /// to save a regular zip archive to a filename with a .exe extension. /// /// Thrown if is non-zero, and the number /// of segments that would be generated for the spanned zip file during the /// save operation exceeds 99. If this happens, you need to increase the /// segment size. ///
public Save ( ) : void
return void

Save() public method

Save the zip archive to the specified stream.

The ZipFile instance is written to storage - typically a zip file in a filesystem, but using this overload, the storage can be anything accessible via a writable stream - only when the caller calls Save.

Use this method to save the zip content to a stream directly. A common scenario is an ASP.NET application that dynamically generates a zip file and allows the browser to download it. The application can call Save(Response.OutputStream) to write a zipfile directly to the output stream, without creating a zip file on the disk on the ASP.NET server.

Be careful when saving a file to a non-seekable stream, including Response.OutputStream. When DotNetZip writes to a non-seekable stream, the zip archive is formatted in such a way that may not be compatible with all zip tools on all platforms. It's a perfectly legal and compliant zip file, but some people have reported problems opening files produced this way using the Mac OS archive utility.

public Save ( Stream outputStream ) : void
outputStream Stream /// The System.IO.Stream to write to. It must be /// writable. If you created the ZipFile instanct by calling /// ZipFile.Read(), this stream must not be the same stream /// you passed to ZipFile.Read(). ///
return void

Save() public method

Save the file to a new zipfile, with the given name.

This method allows the application to explicitly specify the name of the zip file when saving. Use this when creating a new zip file, or when updating a zip archive.

An application can also save a zip archive in several places by calling this method multiple times in succession, with different filenames.

The ZipFile instance is written to storage, typically a zip file in a filesystem, only when the caller calls Save. The Save operation writes the zip content to a temporary file, and then renames the temporary file to the desired name. If necessary, this method will delete a pre-existing file before the rename.

/// Thrown if you specify a directory for the filename. ///
public Save ( String fileName ) : void
fileName String /// The name of the zip archive to save to. Existing files will /// be overwritten with great prejudice. ///
return void

SaveSelfExtractor() public method

Saves the ZipFile instance to a self-extracting zip archive.

The generated exe image will execute on any machine that has the .NET Framework 2.0 installed on it. The generated exe image is also a valid ZIP file, readable with DotNetZip or another Zip library or tool such as WinZip.

There are two "flavors" of self-extracting archive. The WinFormsApplication version will pop up a GUI and allow the user to select a target directory into which to extract. There's also a checkbox allowing the user to specify to overwrite existing files, and another checkbox to allow the user to request that Explorer be opened to see the extracted files after extraction. The other flavor is ConsoleApplication. A self-extractor generated with that flavor setting will run from the command line. It accepts command-line options to set the overwrite behavior, and to specify the target extraction directory.

There are a few temporary files created during the saving to a self-extracting zip. These files are created in the directory pointed to by ZipFile.TempFileFolder, which defaults to . These temporary files are removed upon successful completion of this method.

When a user runs the WinForms SFX, the user's personal directory (Environment.SpecialFolder.Personal) will be used as the default extract location. If you want to set the default extract location, you should use the other overload of SaveSelfExtractor()/ The user who runs the SFX will have the opportunity to change the extract directory before extracting. When the user runs the Command-Line SFX, the user must explicitly specify the directory to which to extract. The .NET Framework 2.0 is required on the computer when the self-extracting archive is run.

NB: This method is not available in the version of DotNetZip build for the .NET Compact Framework, nor in the "Reduced" DotNetZip library.

public SaveSelfExtractor ( string exeToGenerate, SelfExtractorFlavor flavor ) : void
exeToGenerate string /// a pathname, possibly fully qualified, to be created. Typically it /// will end in an .exe extension.
flavor SelfExtractorFlavor /// Indicates whether a Winforms or Console self-extractor is /// desired.
return void

SaveSelfExtractor() public method

Saves the ZipFile instance to a self-extracting zip archive, using the specified save options.

This method saves a self extracting archive, using the specified save options. These options include the flavor of the SFX, the default extract directory, the icon file, and so on. See the documentation for SaveSelfExtractor(string , SelfExtractorFlavor) for more details.

The user who runs the SFX will have the opportunity to change the extract directory before extracting. If at the time of extraction, the specified directory does not exist, the SFX will create the directory before extracting the files.

public SaveSelfExtractor ( string exeToGenerate, SelfExtractorSaveOptions options ) : void
exeToGenerate string The name of the EXE to generate.
options SelfExtractorSaveOptions provides the options for creating the /// Self-extracting archive.
return void

SelectEntries() public method

Retrieve entries from the zipfile by specified criteria.

This method allows callers to retrieve the collection of entries from the zipfile that fit the specified criteria. The criteria are described in a string format, and can include patterns for the filename; constraints on the size of the entry; constraints on the last modified, created, or last accessed time for the file described by the entry; or the attributes of the entry.

For details on the syntax for the selectionCriteria parameter, see .

This method is intended for use with a ZipFile that has been read from storage. When creating a new ZipFile, this method will work only after the ZipArchive has been Saved to the disk (the ZipFile class subsequently and implicitly reads the Zip archive from storage.) Calling SelectEntries on a ZipFile that has not yet been saved will deliver undefined results.

/// Thrown if selectionCriteria has an invalid syntax. ///
public SelectEntries ( String selectionCriteria ) : ICollection
selectionCriteria String the string that specifies which entries to select
return ICollection

SelectEntries() public method

Retrieve entries from the zipfile by specified criteria.

This method allows callers to retrieve the collection of entries from the zipfile that fit the specified criteria. The criteria are described in a string format, and can include patterns for the filename; constraints on the size of the entry; constraints on the last modified, created, or last accessed time for the file described by the entry; or the attributes of the entry.

For details on the syntax for the selectionCriteria parameter, see .

This method is intended for use with a ZipFile that has been read from storage. When creating a new ZipFile, this method will work only after the ZipArchive has been Saved to the disk (the ZipFile class subsequently and implicitly reads the Zip archive from storage.) Calling SelectEntries on a ZipFile that has not yet been saved will deliver undefined results.

/// Thrown if selectionCriteria has an invalid syntax. ///
public SelectEntries ( String selectionCriteria, string directoryPathInArchive ) : ICollection
selectionCriteria String the string that specifies which entries to select
directoryPathInArchive string /// the directory in the archive from which to select entries. If null, then /// all directories in the archive are used. ///
return ICollection

UpdateDirectory() public method

Add or update a directory in a zip archive.
If the specified directory does not exist in the archive, then this method is equivalent to calling AddDirectory(). If the specified directory already exists in the archive, then this method updates any existing entries, and adds any new entries. Any entries that are in the zip archive but not in the specified directory, are left alone. In other words, the contents of the zip file will be a union of the previous contents and the new files.
public UpdateDirectory ( string directoryName ) : ZipEntry
directoryName string /// The path to the directory to be added to the zip archive, or updated in /// the zip archive. ///
return ZipEntry

UpdateDirectory() public method

Add or update a directory in the zip archive at the specified root directory in the archive.
If the specified directory does not exist in the archive, then this method is equivalent to calling AddDirectory(). If the specified directory already exists in the archive, then this method updates any existing entries, and adds any new entries. Any entries that are in the zip archive but not in the specified directory, are left alone. In other words, the contents of the zip file will be a union of the previous contents and the new files.
public UpdateDirectory ( string directoryName, String directoryPathInArchive ) : ZipEntry
directoryName string /// The path to the directory to be added to the zip archive, or updated /// in the zip archive. ///
directoryPathInArchive String /// Specifies a directory path to use to override any path in the /// directoryName. This path may, or may not, correspond to a real /// directory in the current filesystem. If the files within the zip are /// later extracted, this is the path used for the extracted file. Passing /// null (Nothing in VB) will use the path on the /// directoryName, if any. Passing the empty string ("") will insert /// the item at the root path within the archive. ///
return ZipEntry

UpdateEntry() public method

Updates the given entry in the ZipFile, using the given delegates to open and close the stream that provides the content for the ZipEntry.
Calling this method is equivalent to removing the ZipEntry for the given file name and directory path, if it exists, and then calling . See the documentation for that method for further explanation.
public UpdateEntry ( string entryName, OpenDelegate opener, CloseDelegate closer ) : ZipEntry
entryName string /// The name, including any path, to use within the archive for the entry. ///
opener OpenDelegate /// the delegate that will be invoked to open the stream ///
closer CloseDelegate /// the delegate that will be invoked to close the stream ///
return ZipEntry

UpdateEntry() public method

Updates the given entry in the ZipFile, using the given stream as input, and the given filename and given directory Path.

Calling the method is equivalent to calling RemoveEntry() if an entry by the same name already exists, and then calling AddEntry() with the given fileName and stream.

The stream must be open and readable during the call to ZipFile.Save. You can dispense the stream on a just-in-time basis using the ZipEntry.InputStream property. Check the documentation of that property for more information.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

public UpdateEntry ( string entryName, Stream stream ) : ZipEntry
entryName string /// The name, including any path, to use within the archive for the entry. ///
stream Stream The input stream from which to read file data.
return ZipEntry

UpdateEntry() public method

Updates the given entry in the ZipFile, using the given delegate as the source for content for the ZipEntry.
Calling this method is equivalent to removing the ZipEntry for the given file name and directory path, if it exists, and then calling . See the documentation for that method for further explanation.
public UpdateEntry ( string entryName, WriteDelegate writer ) : ZipEntry
entryName string /// The name, including any path, to use within the archive for the entry. ///
writer WriteDelegate the delegate which will write the entry content.
return ZipEntry

UpdateEntry() public method

Updates the given entry in the ZipFile, using the given byte array as content for the entry.
Calling this method is equivalent to removing the ZipEntry for the given filename and directory path, if it exists, and then calling AddEntry(String,byte[]). See the documentation for that method for further explanation.
public UpdateEntry ( string entryName, byte byteContent ) : ZipEntry
entryName string /// The name, including any path, to use within the archive for the entry. ///
byteContent byte The content to use for the ZipEntry.
return ZipEntry

UpdateEntry() public method

Updates the given entry in the ZipFile, using the given string as content for the ZipEntry.

Calling this method is equivalent to removing the ZipEntry for the given file name and directory path, if it exists, and then calling AddEntry(String,String). See the documentation for that method for further explanation. The string content is encoded using the default encoding for the machine, or on Silverlight, using UTF-8. This encoding is distinct from the encoding used for the filename itself. See AlternateEncoding.

public UpdateEntry ( string entryName, string content ) : ZipEntry
entryName string /// The name, including any path, to use within the archive for the entry. ///
content string /// The content of the file, should it be extracted from the zip. ///
return ZipEntry

UpdateEntry() public method

Updates the given entry in the ZipFile, using the given string as content for the ZipEntry.
Calling this method is equivalent to removing the ZipEntry for the given file name and directory path, if it exists, and then calling . See the documentation for that method for further explanation.
public UpdateEntry ( string entryName, string content, System encoding ) : ZipEntry
entryName string /// The name, including any path, to use within the archive for the entry. ///
content string /// The content of the file, should it be extracted from the zip. ///
encoding System /// The text encoding to use when encoding the string. Be aware: This is /// distinct from the text encoding used to encode the filename. See . ///
return ZipEntry

UpdateFile() public method

Adds or Updates a File in a Zip file archive.

This method adds a file to a zip archive, or, if the file already exists in the zip archive, this method Updates the content of that given filename in the zip archive. The UpdateFile method might more accurately be called "AddOrUpdateFile".

Upon success, there is no way for the application to learn whether the file was added versus updated.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

public UpdateFile ( string fileName ) : ZipEntry
fileName string /// The name of the file to add or update. It should refer to a file in the /// filesystem. The name of the file may be a relative path or a /// fully-qualified path. ///
return ZipEntry

UpdateFile() public method

Adds or Updates a File in a Zip file archive.

This method adds a file to a zip archive, or, if the file already exists in the zip archive, this method Updates the content of that given filename in the zip archive.

This version of the method allows the caller to explicitly specify the directory path to be used in the archive. The entry to be added or updated is found by using the specified directory path, combined with the basename of the specified filename.

Upon success, there is no way for the application to learn if the file was added versus updated.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

public UpdateFile ( string fileName, String directoryPathInArchive ) : ZipEntry
fileName string /// The name of the file to add or update. It should refer to a file in the /// filesystem. The name of the file may be a relative path or a /// fully-qualified path. ///
directoryPathInArchive String /// Specifies a directory path to use to override any path in the /// fileName. This path may, or may not, correspond to a real /// directory in the current filesystem. If the files within the zip are /// later extracted, this is the path used for the extracted file. Passing /// null (Nothing in VB) will use the path on the /// fileName, if any. Passing the empty string ("") will insert the /// item at the root path within the archive. ///
return ZipEntry

UpdateFiles() public method

Adds or updates a set of files in the ZipFile.

Any files that already exist in the archive are updated. Any files that don't yet exist in the archive are added.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to each ZipEntry added.

public UpdateFiles ( System fileNames ) : void
fileNames System /// The collection of names of the files to update. Each string should refer to a file in /// the filesystem. The name of the file may be a relative path or a fully-qualified path. ///
return void

UpdateFiles() public method

Adds or updates a set of files to the ZipFile, using the specified directory path in the archive.

Any files that already exist in the archive are updated. Any files that don't yet exist in the archive are added.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to each ZipEntry added.

public UpdateFiles ( System fileNames, String directoryPathInArchive ) : void
fileNames System /// The names of the files to add or update. Each string should refer to a /// file in the filesystem. The name of the file may be a relative path or a /// fully-qualified path. ///
directoryPathInArchive String /// Specifies a directory path to use to override any path in the file name. /// This path may, or may not, correspond to a real directory in the current /// filesystem. If the files within the zip are later extracted, this is the /// path used for the extracted file. Passing null (Nothing in /// VB) will use the path on each of the fileNames, if any. Passing /// the empty string ("") will insert the item at the root path within the /// archive. ///
return void

UpdateItem() public method

Add or update a file or directory in the zip archive.

This is useful when the application is not sure or does not care if the item to be added is a file or directory, and does not know or does not care if the item already exists in the ZipFile. Calling this method is equivalent to calling RemoveEntry() if an entry by the same name already exists, followed calling by AddItem().

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

public UpdateItem ( string itemName ) : void
itemName string /// the path to the file or directory to be added or updated. ///
return void

UpdateItem() public method

Add or update a file or directory.

This method is useful when the application is not sure or does not care if the item to be added is a file or directory, and does not know or does not care if the item already exists in the ZipFile. Calling this method is equivalent to calling RemoveEntry(), if an entry by that name exists, and then calling AddItem().

This version of the method allows the caller to explicitly specify the directory path to be used for the item being added to the archive. The entry or entries that are added or updated will use the specified DirectoryPathInArchive. Extracting the entry from the archive will result in a file stored in that directory path.

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

public UpdateItem ( string itemName, string directoryPathInArchive ) : void
itemName string /// The path for the File or Directory to be added or updated. ///
directoryPathInArchive string /// Specifies a directory path to use to override any path in the /// itemName. This path may, or may not, correspond to a real /// directory in the current filesystem. If the files within the zip are /// later extracted, this is the path used for the extracted file. Passing /// null (Nothing in VB) will use the path on the /// itemName, if any. Passing the empty string ("") will insert the /// item at the root path within the archive. ///
return void

UpdateSelectedFiles() public method

Updates the ZipFile with a selection of files from the disk that conform to the specified criteria.
This method selects files from the specified disk directory that match the specified selection criteria, and Updates the ZipFile with those files, using the specified directory path in the archive. If recurseDirectories is true, files are also selected from subdirectories, and the directory structure in the filesystem is reproduced in the zip archive, rooted at the directory specified by directoryOnDisk. For details on the syntax for the selectionCriteria parameter, see AddSelectedFiles(String).
public UpdateSelectedFiles ( String selectionCriteria, String directoryOnDisk, String directoryPathInArchive, bool recurseDirectories ) : void
selectionCriteria String /// The criteria for selection of files to add to the ZipFile. ///
directoryOnDisk String /// The path to the directory in the filesystem from which to select files. ///
directoryPathInArchive String /// Specifies a directory path to use to in place of the /// directoryOnDisk. This path may, or may not, correspond to a /// real directory in the current filesystem. If the files within the zip /// are later extracted, this is the path used for the extracted file. /// Passing null (nothing in VB) will use the path on the file name, if /// any; in other words it would use directoryOnDisk, plus any /// subdirectory. Passing the empty string ("") will insert the item at /// the root path within the archive. ///
recurseDirectories bool /// If true, the method also scans subdirectories for files matching the criteria. ///
return void