Skip to main content

How to: Cancel Archivation

To provide the capability to cancel an archiving process after it has been started, do the following:

  1. Create a ZipArchive class instance.
  2. Subscribe to the ZipArchive.Progress event.
  3. Set the CanContinueEventArgs.CanContinue property of event arguments to false, in case you decide to stop the operation.
  4. Call the ZipArchive.AddFile method for each selected file.
  5. Call the ZipArchive.Save method to create an archive and save it to a specified location.

View Example

using DevExpress.Compression;
        volatile bool stopProgress = false;

        public void CancelArchiveProgress() {
            string[] sourcefiles = this.sourceFiles;
            using (ZipArchive archive = new ZipArchive()) {
                archive.Progress += archive_Progress;
                foreach (string file in sourceFiles) {
                    archive.AddFile(file, "/");
                }
                archive.Save("Documents\\CancelArchiveProgress.zip");
            }
        }

        private void archive_Progress(object sender, ProgressEventArgs args) {
            args.CanContinue = !this.stopProgress;
        }