我正试图从用户那里压缩并加密所选文件。一切都很好,除了我正在压缩整个路径,即不是文件本身。下面是我的代码,关于如何在所选文件上进行压缩和加密的任何帮助。
openFileDialog1.ShowDialog();
var fileName = string.Format(openFileDialog1.FileName);
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
using (ZipFile zip = new ZipFile())
{
zip.Password = "test1";
zip.Encryption = EncryptionAlgorithm.WinZipAes256;
zip.AddFile(fileName);
zip.Save(path + "\\test.ZIP");
MessageBox.Show("File Zipped!", "Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
}发布于 2014-04-29 07:09:56
必须为zip存档显式设置文件名:
zip.AddFile(fileName).FileName = System.IO.Path.GetFileName(fileName);发布于 2014-04-29 07:23:23
这就是如何压缩文件,并在存档中重命名它。提取后,将使用新名称创建文件。
using (ZipFile zip1 = new ZipFile())
{
string newName= fileToZip + "-renamed";
zip1.AddFile(fileToZip).FileName = newName;
zip1.Save(archiveName);
}参考资料:C#实例
https://stackoverflow.com/questions/23357743
复制相似问题