0

I use DotNetZip for zip file in c#. and i can create zip file with password with this code:

using (ZipFile zip = new ZipFile()
{
    zip.Password = "password";
    zip.AddDirectory(path);
    zip.Save(outputPath);
}

I with using this code zip file my directory or file. but i want set password in my zip file.

So, I using this code:

using (ZipFile zip = new ZipFile("MyFile.zip")
{
    zip.Password = "password";
    zip.Save();
}

but it's not working.

Daniel
  • 9,491
  • 12
  • 50
  • 66
mishi caro
  • 23
  • 1
  • 7
  • It has already been answered here. https://stackoverflow.com/questions/40115705/set-password-on-zip-file-using-dotnetzip – avinash Feb 19 '19 at 05:43
  • this article using create zipfile with password. but i have zip file. I want set password in zipfile – mishi caro Feb 19 '19 at 05:49

1 Answers1

0

The following is a sample code for file encyption. Hope this will solve your problem.

// create a file with encryption
using (ZipFile zip = new ZipFile())
{
    zip.AddFile("ReadMe.txt");
    zip.Password= "!Secret1";
    zip.AddFile("MapToTheSite-7440-N49th.png");
    zip.AddFile("2008-Regional-Sales-Report.pdf");
    zip.Save("EncryptedArchive.zip");
}

// extract entries that use encryption
using (ZipFile zip = ZipFile.Read("EncryptedArchive.zip"))
{
    zip.Password= "!Secret1";
    zip.ExtractAll("extractDir");
}
Hemanth
  • 91
  • 1
  • 8