如何设置zip文件夹最佳压缩并为Zip文件夹设置密码,我使用的代码很少,请帮我解决如何为zip文件夹设置最佳压缩和密码。
using (var zipStream = new MemoryStream())
{
zipFile.Save(zipStream);
zipStream.Seek(0, SeekOrigin.Begin);
CloudBlockBlob cblob = container.GetBlockBlobReference("MockTestZip/MT-" + this.mockExamId + ".zip");
cblob.UploadFromStream(zipStream);
}
我刚刚在其中添加了这两行,但密码未在azure blob存储区的zip文件夹中设置
zipFile.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
zipFile.Password = "encrypt";
答案 0 :(得分:0)
根据您的描述,我利用DotNetZip version 1.10.1来测试这个问题。以下是关于Password
中ZipFile
属性的评论:
编写zip存档时,此密码将应用于条目,而不是zip存档本身。它适用于随后添加到ZipFile的任何ZipEntry, 使用AddFile,AddDirectory,AddEntry或AddItem方法之一等。
根据您的情况,我假设您可以将文件存储在没有密码的zip文件中,然后将zip文件存储在第二个外部zip文件中,密码如下:
using (ZipFile zipFile = new ZipFile())
{
zipFile.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
zipFile.Password = "{your-password}";
zipFile.AddFile(@"inner.zip",""); //Passing the empty string ("") to store your zip file at the root path within the archive.
using (var zipStream = new MemoryStream())
{
zipFile.Save(zipStream);
zipStream.Seek(0, SeekOrigin.Begin);
CloudBlockBlob cblob = container.GetBlockBlobReference("MockTestZip/MT-" + this.mockExamId + ".zip");
cblob.UploadFromStream(zipStream);
}
}