ZipErrorAction Property

DotNetZip

Ionic Zip Library v1.9.1.6 ZipErrorAction Property
ReferenceIonic.ZipZipFileZipErrorAction
The action the library should take when an error is encountered while opening or reading files as they are saved into a zip archive.
Declaration Syntax
C# Visual Basic Visual C++
public ZipErrorAction ZipErrorAction { get; set; }
Public Property ZipErrorAction As ZipErrorAction
	Get
	Set
public:
property ZipErrorAction ZipErrorAction {
	ZipErrorAction get ();
	void set (ZipErrorAction value);
}
Remarks

Errors can occur as a file is being saved to the zip archive. For example, the File.Open may fail, or a File.Read may fail, because of lock conflicts or other reasons.

The first problem might occur after having called AddDirectory() on a directory that contains a Clipper .dbf file; the file is locked by Clipper and cannot be opened for read by another process. An example of the second problem might occur when trying to zip a .pst file that is in use by Microsoft Outlook. Outlook locks a range on the file, which allows other processes to open the file, but not read it in its entirety.

This property tells DotNetZip what you would like to do in the case of these errors. The primary options are: ZipErrorAction.Throw to throw an exception (this is the default behavior if you don't set this property); ZipErrorAction.Skip to Skip the file for which there was an error and continue saving; ZipErrorAction.Retry to Retry the entry that caused the problem; or ZipErrorAction.InvokeErrorEvent to invoke an event handler.

This property is implicitly set to ZipErrorAction.InvokeErrorEvent if you add a handler to the ZipError event. If you set this property to something other than ZipErrorAction.InvokeErrorEvent, then the ZipError event is implicitly cleared. What it means is you can set one or the other (or neither), depending on what you want, but you never need to set both.

As with some other properties on the ZipFile class, like Password, Encryption, and CompressionLevel, setting this property on a ZipFile instance will cause the specified ZipErrorAction to be used on all ZipEntry items that are subsequently added to the ZipFile instance. If you set this property after you have added items to the ZipFile, but before you have called Save(), those items will not use the specified error handling action.

If you want to handle any errors that occur with any entry in the zip file in the same way, then set this property once, before adding any entries to the zip archive.

If you set this property to ZipErrorAction.Skip and you'd like to learn which files may have been skipped after a Save(), you can set the StatusMessageTextWriter on the ZipFile before calling Save(). A message will be emitted into that writer for each skipped file, if any.

Examples
This example shows how to tell DotNetZip to skip any files for which an error is generated during the Save().
CopyVB.NET
Public Sub SaveZipFile()
    Dim SourceFolder As String = "fodder"
    Dim DestFile As String =  "eHandler.zip"
    Dim sw as New StringWriter
    Using zipArchive As ZipFile = New ZipFile
        ' Tell DotNetZip to skip any files for which it encounters an error
        zipArchive.ZipErrorAction = ZipErrorAction.Skip
        zipArchive.StatusMessageTextWriter = sw
        zipArchive.AddDirectory(SourceFolder)
        zipArchive.Save(DestFile)
    End Using
    ' examine sw here to see any messages
End Sub

Assembly: Ionic.Zip (Module: Ionic.Zip) Version: 1.9.1.8 (1.9.1.8)