How to password protect ZIP file

0 votes
asked Oct 12, 2010 by Rebex KB (7,480 points)
edited Oct 12, 2010

I want to create a ZIP file which is password protected.

How to do it using Rebex ZIP?

Applies to: Rebex ZIP

2 Answers

0 votes
answered Oct 12, 2010 by Rebex KB (7,480 points)
edited Oct 12, 2010
 
Best answer

Following C# code shows how to create a password protected ZIP file and add files to it.

// create new ZIP archive 
using (ZipArchive zip = new ZipArchive(@"C:\archive.zip", ArchiveOpenMode.Create))
{
    // set the Password first 
    zip.Password = "PASSword#123";

    // now add all files from the folder c:\data
    zip.Add(@"C:\Data");
}
0 votes
answered Oct 12, 2010 by Rebex KB (7,480 points)
edited Oct 12, 2010

Following VB.NET code shows how to create a password protected ZIP file and ad files to it.

' create new ZIP archive 
Using zip As New ZipArchive("C:\archive.zip", ArchiveOpenMode.Create)
    ' set the Password first 
    zip.Password = "PASSword#123"

    ' now add files from the folder c:\data
    zip.Add("C:\Data")
End Using 
...