Arsalan Sherwani
Arsalan Sherwani

Reputation: 560

Decrypting a Password Protected Zipped File using DotNetZip C#

I m trying to extract a zipped file through DotNetZip. The file is encrypted with a password and needs to be either reset or removed. I used ExtractAll method but received exception:

BadPasswordException was unhandled, the password didnot match.

My code is below:

using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(source_file))
{
    zip.Password = "1234";
    zip.ExtractAll(dest_path, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently);
}

Any help will be appreciated.

Upvotes: 1

Views: 2373

Answers (1)

Multi1209
Multi1209

Reputation: 121

According to the documentation use

using (ZipFile zip = ZipFile.Read(ExistingZipFile))
{
    ZipEntry e = zip["TaxInformation-2008.xls"];
    e.ExtractWithPassword(BaseDirectory, Password);
}

http://dotnetzip.herobo.com/DNZHelp/Index.html

Upvotes: 1

Related Questions