System.IO.Compression.ZipFile.ExtractToDirectory(zipPath, extractPath);
在C#中使用ZipFile中,我試圖從已知位置提取文件,並拋出以下錯誤: System.IO.Exception:郵編條目名稱以目錄分隔符結尾,但包含數據ZIP條目名稱在目錄分隔符結束,但包含數據
我已經完成了一些研究,ExtractToDirectory在MSDN中進行了解釋,但無法找到此錯誤定義。你能解釋爲什麼這個錯誤發生了嗎?
從MSDN:
IOException異常
The directory specified by destinationDirectoryName already exists.
- 或 -
在歸檔中的條目的名稱爲空,僅包含空白,或至少包含一個無效字符。
- 或 -
Extracting an archive entry would create a file that is outside the directory specified by destinationDirectoryName. (For example, this might happen if the entry name contains parent directory accessors.)
- 或 -
An archive entry to extract has the same name as an entry that has already been extracted from the same archive.
我想這主要是指存儲於zip壓縮文件或者包含'..'或在'\'結束的文件名。你確定你不會弄亂路徑,例如使用目標路徑作爲zip存檔內部路徑? – Mario
花了幾個小時後發現的一件事是,這個問題與zip文件的生成方式有關。 爲了解決問題,我使用7-zip生成zip文件。使用winRar生成zip文件解決了這個問題。 我仍然不知道它的根本原因。 – erenalgan
@Mario,這也是我最初的猜測。不過,我還沒有發現有關路徑的任何問題(感謝評論)。 – erenalgan