[英]C# .net4.5 Unpack Zip file
我已經制作了一個自動更新系統,在我下載zip文件之后,我想要解壓縮。 如果我使用簡單的解壓縮,它的工作。
//System.IO.Compression.ZipFile.ExtractToDirectory(zipPath,extractPath);
但是當我想覆蓋文件時,應用程序會一直崩潰。 “mscorlib.dll中出現類型'System.IO.IOException'的異常,但未在用戶代碼中處理”“文件名,foldername或標簽語法不正確。”
string zipPath = @""+ System.IO.Directory.GetCurrentDirectory() + "/Temp/"+"1.zip";
string extractPath = @""+ System.IO.Directory.GetCurrentDirectory();
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
entry.ExtractToFile(Path.Combine(extractPath, entry.FullName),true);
}
}
我無法弄清楚問題是什么。 我用的是壞事嗎?
string zipPath = @""+ System.IO.Directory.GetCurrentDirectory() + "/Temp/"+ currentupdate+".zip";
string extractPath = @""+ System.IO.Directory.GetCurrentDirectory() + "/Temp";
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
string fullPath = Path.Combine(extractPath, entry.FullName);
if (String.IsNullOrEmpty(entry.Name))
{
Directory.CreateDirectory(fullPath);
}
else
{
entry.ExtractToFile(fullPath,true);
}
}
}
這是正確的解決方案。 謝謝您的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.