Skip to main content
A newer version of this page is available. .

ZipArchive.Error Event

Fires when an error occurs while adding files to the archive, processing archive items or saving the archive.

Namespace: DevExpress.Compression

Assembly: DevExpress.Docs.v18.2.dll

Declaration

public event ErrorEventHandler Error

Event Data

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.

Remarks

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;
            }
        }

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.

See Also