To extract (unzip) a password protected zip file using the Ionic DotNetZip Library, you can use the snippet below.

Samples

[tab name=”C# Sample”]

string zipFile = @"C:\Users\Fesslersoft\Desktop\ZipTest\Test.zip";
string targetDirectory = @"C:\Users\Fesslersoft\Desktop\ZipTest\";

using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(zipFile))
{
	zip.Password = "1234";
	zip.ExtractAll(targetDirectory, Ionic.Zip.ExtractExistingFileAction.DoNotOverwrite);
}

Console.WriteLine("Zip file has been successfully extracted.");
Console.Read();

[/tab]
[tab name=”VB.NET Sample”]

Dim zipFile As String = "C:\Users\Fesslersoft\Desktop\ZipTest\Test.zip"
Dim targetDirectory As String = "C:\Users\Fesslersoft\Desktop\ZipTest\" 

Using zip As Ionic.Zip.ZipFile = Ionic.Zip.ZipFile.Read(zipFile)
	zip.Password = "1234"
	zip.ExtractAll(targetDirectory, Ionic.Zip.ExtractExistingFileAction.DoNotOverwrite)
End Using

Console.WriteLine("Zip file has been successfully extracted.")
Console.Read()

[/tab]

[end_tabset]

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Leave a Reply