ZipArchive.ItemAdding Event
Occurs before a zip item is added to the archive.
Namespace: DevExpress.Compression
Assembly: DevExpress.Docs.v24.1.dll
NuGet Package: DevExpress.Document.Processor
Declaration
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("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;
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ItemAdding 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.