Skip to main content

ZipItem.Extract(String, AllowFileOverwriteMode) Method

Extracts the current archive item as a file into the specified directory and enables you to define the behavior in case of a file name conflict.

Namespace: DevExpress.Compression

Assembly: DevExpress.Docs.v24.1.dll

NuGet Package: DevExpress.Document.Processor


public void Extract(
    string directory,
    AllowFileOverwriteMode allowFileOverwrite


Name Type Description
directory String

A string that is the path to the directory to which the files are extracted.

allowFileOverwrite AllowFileOverwriteMode

An AllowFileOverwriteMode enumeration member that specifies the behavior if a file name conflict occurs.


If the archive contains directories, the directory structure will be recreated in the specified directory. The ZipItem.Name property value becomes the file name of the extracted file. If a file with the same name already exists, a file name conflict occurs. In this situation, the AllowFileOverwriteMode parameter specifies the default action.

This example illustrates how to handle a file name conflict when files are extracted from archive. If a file with the same name exists, the ZipArchive.AllowFileOverwrite event occurs. You can handle this event and determine that if the file in the folder is newer than the zip item, the file in the folder should not be overwritten.

View Example

using DevExpress.Compression;

public void UnzipArchiveConflict() {
    string pathToZipArchive = "Documents\\";
    string pathToExtract = "Documents\\!Extracted";
    using (ZipArchive archive = ZipArchive.Read(pathToZipArchive)) {
        archive.OptionsBehavior.AllowFileOverwrite = AllowFileOverwriteMode.Custom;
        archive.AllowFileOverwrite += archive_AllowFileOverwrite;
        foreach (ZipItem item in archive) {

private void archive_AllowFileOverwrite(object sender, AllowFileOverwriteEventArgs e) {
    FileInfo fi = new FileInfo(e.TargetFilePath);
    if (e.ZipItem.LastWriteTime < fi.LastWriteTime) e.Cancel = true;
See Also