ZipArchive.OnOverwrite Event


Occurs when an existed file will be overwrited.

[Visual Basic]
Public Event OnOverwrite As OnOverwriteEventHandler
Public Delegate Sub OnOverwriteEventHandler( _
    ByVal sender As Object, _
    ByVal z As ZipFile, _
    ByVal target As String, _
    ByRef overwrite As Boolean _
)
[C#]
public event OnOverwriteEventHandler OnOverwrite;
public delegate void OnOverwriteEventHandler( 
     object sender, 
     ZipFile z,
     string target,
     ref bool overwrite 
);
[C++]
public: __event OnOverwriteEventHandler* OnOverwrite;
public __gc __delegate void OnOverwriteEventHandler( 
     Object* sender, 
     ZipFile* z,
     String* target,
     bool __gc *overwrite 
);
[JScript] In JScript, you can handle the events defined by a class. However, you cannot define your own.

Event Data

sender
The source (ZipArchive instance) of the event.
z
The (ZipFile instance) being extracted.
target
Full name of the existed file.
overwrite
Gets or sets a value indicating whether the file should be overwritten.

Example

[Visual Basic, C#, C++] To get the full samples of EACompression, please refer to Samples section.

[Visual Basic]
Imports EACompression
Imports System.IO

Module Module1
    Sub Main()
        Try
            Dim oZip As New ZipArchive("TryIt")
            AddHandler oZip.OnOverwrite, AddressOf OnOverwrite
            
            oZip.Load("c:\test.zip")
            Dim password As String = ""
            oZip.ExtractAll( "c:\unzipped", password )
            
        Catch ep As Exception
            Console.Write(ep.Message)
        End Try
    End Sub

    Sub OnOverwrite( _
    ByVal sender As Object, _
    ByVal z As ZipFile, _
    ByVal target As String, _
    ByRef overwrite As Boolean _
)
        'overwrite = True 'will overwrite existed file
    End Sub
End Module

[C#]
using System;
using EACompression;
using System.IO;

namespace test
{
    class Class1
    {
        public static void OnOverwrite( 
            object sender, 
            ZipFile z, 
            string target, 
            ref bool overwrite )
        {
            //overwrite = true; // will overwrite the existed file.
        }
        
        [STAThread]
        static void Main(string[] args)
        {
            try
            {
                ZipArchive oZip = new ZipArchive( "TryIt" );
                oZip.OnOverwrite += new ZipArchive.OnOverwriteEventHandler( OnOverwrite );
                
                oZip.Load( "c:\\test.zip" );
                string password = "";
                oZip.ExtractAll( "c:\\unzipped", password );
            
            }
            catch( Exception ep )
            {
                Console.Write( ep.Message );
            }       
        }   
    }
}

[C++]
using namespace System;
using namespace System::IO;
using namespace EACompression;

public __gc class ZipArchiveEventHandler
{
public:
    static void OnOverwrite( 
        Object* sender, 
        ZipFile* z,
        String* target,
        bool __gc *overwrite 
    )
    {
        //*overwrite = true; // will overwrite the existed file.
    }
};

int _tmain()
{
    try
    {
       ZipArchive *oZip = new ZipArchive( S"TryIt" );
       oZip->OnOverwrite += new ZipArchive::OnOverwriteEventHandler( NULL, &ZipArchiveEventHandler::OnOverwrite );
       oZip->Load( S"c:\\test.zip" );
    
        String *password = S"";
        oZip->ExtractAll( S"c:\\uuzipped", password );
    }
    catch( Exception *ep )
    {
        Console::Write( ep->Message );
    }
    return 0;
}

See Also

Handle file overwriting and path structure
Encrypt and decrypt file with password