A newer version of this page is available. Switch to the current version.

ZipArchive.ItemAdding Event

Occurs before a zip item is added to the archive.

Namespace: DevExpress.Compression

Assembly: DevExpress.Docs.v18.2.dll

Declaration

public event ZipItemAddingEventHandler ItemAdding

Event Data

The ItemAdding event's data class is ZipItemAddingEventArgs. The following properties provide information specific to this event:

Property Description
Action Gets or sets the action required to perform after the ItemAdding event is handled.
Item Obtains the zip item being added to the archive.

Remarks

By handling the ItemAdding event you can decide whether or not a certain item should be added to the archive. The item is accessible by using the ZipItemAddingEventArgs.Item property. The ZipItemAddingEventArgs.Action property allows you to skip the current item or to stop adding items to the archive.

This example demonstrates how to handle the ZipArchive.ItemAdding event to decide for each file whether it should be included in the archive.

If a file creation date is not the current date, the file is not added to the archive. A volatile variable is used to indicate whether the process should be stopped - it can be useful to interrupt archive creation if too many files are specified.

using DevExpress.Compression;
        volatile bool stopArchiving = false;
        public void FilterArchiveFiles() {
            string[] sourcefiles = this.sourceFiles;
            using (ZipArchive archive = new ZipArchive()) {
                archive.ItemAdding += archive_ItemAdding;
                foreach (string file in sourceFiles) {
                    archive.AddFile(file, "/");
                }
                archive.Save("Documents\\FilterArchiveFiles.zip");
            }
        }

        private void archive_ItemAdding(object sender, ZipItemAddingEventArgs args) {
            if (args.Item.CreationTime.Date != DateTime.Today)
                args.Action = ZipItemAddingAction.Cancel;
            if (stopArchiving) args.Action = ZipItemAddingAction.Stop;
        }
See Also