Occurs when the decrypting password is incorrect, you can use this event to correct the password.
[Visual Basic] Public Event OnPasswordError As OnPasswordErrorEventHandler Public Delegate Sub OnPasswordErrorEventHandler( _ ByVal sender As Object, _ ByVal z As ZipFile, _ ByRef password As String _ )
[C#] public event OnPasswordErrorEventHandler OnPasswordError; public delegate void OnPasswordErrorEventHandler( object sender, ZipFile z, ref string password );
[C++] public: __event OnPasswordErrorEventHandler* OnPasswordError; public __gc __delegate void OnPasswordErrorEventHandler( Object* sender, ZipFile* z, String** password );
Event Data
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.OnPasswordError, AddressOf OnPasswordError oZip.Load("c:\test.zip") Dim password As String = "badpassword" oZip.ExtractAll( "c:\unzipped", password ) Catch ep As Exception Console.Write(ep.Message) End Try End Sub Sub OnPasswordError( _ ByVal sender As Object, _ ByVal z As ZipFile, _ ByRef password As String _ ) password = "correctpassword" End Sub End Module [C#] using System; using EACompression; using System.IO; namespace test { class Class1 { public static void OnPasswordError( object sender, ZipFile z, ref string password ) { password = "correctpassword"; } [STAThread] static void Main(string[] args) { try { ZipArchive oZip = new ZipArchive( "TryIt" ); oZip.OnPasswordError += new ZipArchive.OnPasswordErrorEventHandler( OnPasswordError ); oZip.Load( "c:\\test.zip" ); string password = "badpassword"; 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 OnPasswordError( Object* sender, ZipFile* z, String** password ) { *password = "correctpassword"; } }; int _tmain() { try { ZipArchive *oZip = new ZipArchive( S"TryIt" ); oZip->OnPasswordError += new ZipArchive::OnPasswordErrorEventHandler( NULL, &ZipArchiveEventHandler::OnPasswordError ); oZip->Load( S"c:\\test.zip" ); String *password = S"badpassword"; oZip->ExtractAll( S"c:\\unzipped", password ); } catch( Exception *ep ) { Console::Write( ep->Message ); } return 0; }
See Also
Handle file overwriting and path structure
Encrypt and decrypt file with password