Articles → .NET → Create Password Protected Zip File Using Dotnetzip C#
Create Password Protected Zip File Using Dotnetzip C#
Download DLL
Add A Reference To The Project
Create A File To Zip
Write Code To Zip File
string filePath = @"c:\temp\Book1.xlsx";
using(FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read)) {
using(ZipFile zip = new ZipFile()) {
zip.Password = "test";
zip.AddEntry(filePath, stream);
zip.Save(Path.GetDirectoryName(filePath) + "\\myZIPFile.zip");
}
}
Click to Enlarge