我在我的Pocket PC項目中使用Ionic.Zip(Compact Framework版本)。
提取壓縮文件(使用Ionic.Zip)正常工作。如果我將密碼放在壓縮文件上,它在提取之前需要密碼,但是當我嘗試此實例時,提取的密碼驗證失敗。Ionic.Zip提取文件並忽略密碼
示例:該文件夾即將壓縮。
\MyDevice\My Documents\My Pictures
此文件夾包含兩個文件('Flower.jpg','Waterfall.jpg')
使用此代碼壓縮文件:
public string Compress(string[] Paths, string SaveFileName, string Password, string CompressionType)
{
try
{
using (ZipFile zip = new ZipFile())
{
if (string.IsNullOrEmpty(Password))
zip.Password = Password;
zip.CompressionLevel = Utility.GetCompressionLevel(CompressionType);
foreach (string item in Paths)
{
if (Utility.IsDirectory(item))
zip.AddDirectory(item);
else if (Utility.IsFile(item))
zip.AddFile(item);
}
if (!SaveFileName.Trim().ToLower().EndsWith(".zip"))
if (SaveFileName.Trim().EndsWith("."))
SaveFileName += "zip";
else
SaveFileName += ".zip";
zip.Save(SaveFileName);
}
return Utility.GetResourceString("ZipSuccess");
}
catch (Exception ex)
{
return ex.Message;
}
}
提取代碼:
public string Decompress(string ZipFilePath, string TargetPath, string Password, bool OverwriteExistingFiles)
{
try
{
using (ZipFile decompress = ZipFile.Read(ZipFilePath))
{
if (!string.IsNullOrEmpty(Password))
decompress.Password = Password;
foreach (ZipEntry e in decompress)
{
e.Extract(TargetPath, OverwriteExistingFiles ? ExtractExistingFileAction.OverwriteSilently : ExtractExistingFileAction.DoNotOverwrite);
}
}
return Utility.GetResourceString("ExtractSuccess");
}
catch (Exception ex)
{
return ex.Message;
}
}
提取在此位置文件的偉大工程,因爲它需要密碼:
\MyDevice\My Documents\Personal
但是!當我提取文件在同一文件夾上時:
\MyDevice\My Documents\My Pictures
它提取文件時不需要密碼。
我認爲這是一個錯誤。我能爲此做些什麼?
希望有人能回答。謝謝!
您確定文件被提取?您正在將它們解壓縮到壓縮文件的相同文件夾中。所以文件已經存在於這個文件夾中 – Jehof
是的,我還嘗試在解壓縮之前重命名文件,以確保正在提取文件。我還在foreach循環中放置了斷點,以查看是否收集了要提取的文件。 – fiberOptics
如果你認爲這是一個錯誤,你應該在這裏發佈:http://dotnetzip.codeplex.com/workitem/list/basic –