ExtractExistingFile Property

DotNetZip

Ionic Zip Library v1.9.1.6 ExtractExistingFile Property
ReferenceIonic.ZipZipEntryExtractExistingFile
The action the library should take when extracting a file that already exists.
Declaration Syntax
C# Visual Basic Visual C++
public ExtractExistingFileAction ExtractExistingFile { get; set; }
Public Property ExtractExistingFile As ExtractExistingFileAction
	Get
	Set
public:
property ExtractExistingFileAction ExtractExistingFile {
	ExtractExistingFileAction get ();
	void set (ExtractExistingFileAction value);
}
Remarks

This property affects the behavior of the Extract methods (one of the Extract() or ExtractWithPassword() overloads), when extraction would would overwrite an existing filesystem file. If you do not set this property, the library throws an exception when extracting an entry would overwrite an existing file.

This property has no effect when extracting to a stream, or when the file to be extracted does not already exist.

Examples
This example shows how to set the ExtractExistingFile property in an ExtractProgress event, in response to user input. The ExtractProgress event is invoked if and only if the ExtractExistingFile property was previously set to ExtractExistingFileAction.InvokeExtractProgressEvent.
CopyC#
public static void ExtractProgress(object sender, ExtractProgressEventArgs e)
{
    if (e.EventType == ZipProgressEventType.Extracting_BeforeExtractEntry)
        Console.WriteLine("extract {0} ", e.CurrentEntry.FileName);

    else if (e.EventType == ZipProgressEventType.Extracting_ExtractEntryWouldOverwrite)
    {
        ZipEntry entry = e.CurrentEntry;
        string response = null;
        // Ask the user if he wants overwrite the file
        do
        {
            Console.Write("Overwrite {0} in {1} ? (y/n/C) ", entry.FileName, e.ExtractLocation);
            response = Console.ReadLine();
            Console.WriteLine();

        } while (response != null && response[0]!='Y' &&
                 response[0]!='N' && response[0]!='C');

        if  (response[0]=='C')
            e.Cancel = true;
        else if (response[0]=='Y')
            entry.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently;
        else
            entry.ExtractExistingFile= ExtractExistingFileAction.DoNotOverwrite;
    }
}

Assembly: Ionic.Zip (Module: Ionic.Zip) Version: 1.9.1.8 (1.9.1.8)