officefileapi-devexpress-dot-compression-dot-ziparchive.md
Fires when an error occurs while adding files to the archive, processing archive items or saving the archive.
Namespace : DevExpress.Compression
Assembly : DevExpress.Docs.v25.2.dll
NuGet Package : DevExpress.Document.Processor
public event ErrorEventHandler Error
Public Event Error As ErrorEventHandler
The Error event's data class is ErrorEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| CanContinue | Gets or sets the value that specifies whether the process can proceed further. Inherited from CanContinueEventArgs. |
| ItemName | Obtains the zip item name for which the error occurs. |
The event data class exposes the following methods:
| Method | Description |
|---|---|
| GetException() | Obtains the exception that triggered the error event. |
Use the ErrorEventArgs.GetException method of the event arguments to determine the exception that is the reason for the error. The ErrorEventArgs.ItemName property value is the name of the ZipItem for which an error occurs. If an error occurs when adding a directory to an archive or saving the compressed archive, the name of the ZipItem is empty.
By handling the Error event, you can decide whether to cancel processing a failed item and skip to the next item; otherwise, you can cancel processing the entire archive by setting the CanContinueEventArgs.CanContinue property to false.
using DevExpress.Compression;
public void ArchiveDirectoryWithError() {
string path = this.startupPath;
using (ZipArchive archive = new ZipArchive()) {
archive.Error += archive_Error;
archive.AddDirectory(path);
archive.Save("Documents\\ArchiveDirectoryWithError.zip");
}
}
private void archive_Error(object sender, DevExpress.Compression.ErrorEventArgs args) {
string errorMessage;
Exception e = args.GetException();
if (String.IsNullOrEmpty(args.ItemName)) {
errorMessage = e.Message;
}
else {
errorMessage = String.Format("Item: {0}\n\nDescription:\n{1}", args.ItemName, e.Message);
}
string descriptionMessage = "Click Cancel to abort operation. Click OK to skip the item and continue.";
string message = String.Format("{0}\n{1}", errorMessage, descriptionMessage);
if (MessageBox.Show(message, "Error", MessageBoxButtons.OKCancel) == DialogResult.Cancel) {
args.CanContinue = false;
}
}
Imports DevExpress.Compression
Public Sub ArchiveDirectoryWithError()
Dim path As String = Me.startupPath
Using archive As New ZipArchive()
AddHandler archive.Error, AddressOf archive_Error
archive.AddDirectory(path)
archive.Save("Documents\ArchiveDirectoryWithError.zip")
End Using
End Sub
Private Sub archive_Error(ByVal sender As Object, ByVal args As DevExpress.Compression.ErrorEventArgs)
Dim errorMessage As String
Dim e As Exception = args.GetException()
If String.IsNullOrEmpty(args.ItemName) Then
errorMessage = e.Message
Else
errorMessage = String.Format("Item: {0}" & Constants.vbLf + Constants.vbLf & "Description:" & Constants.vbLf & "{1}", args.ItemName, e.Message)
End If
Dim descriptionMessage As String = "Click Cancel to abort operation. Click OK to skip the item and continue."
Dim message As String = String.Format("{0}" & Constants.vbLf & "{1}", errorMessage, descriptionMessage)
If MessageBox.Show(message, "Error", MessageBoxButtons.OKCancel) = DialogResult.Cancel Then
args.CanContinue = False
End If
End Sub
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Error event.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
zip-compression-and-archive-api-examples/CS/CompressionLibraryExamples/ZipExamples.cs#L48
using (ZipArchive archive = new ZipArchive()) {
archive.Error += archive_Error;
archive.AddDirectory(path);
zip-compression-and-archive-api-examples/VB/CompressionLibraryExamples/ZipExamples.vb#L48
Using archive As New ZipArchive()
AddHandler archive.Error, AddressOf archive_Error
archive.AddDirectory(path)
See Also