在Windows中解压缩文件时,我偶尔会遇到路径问题
使用DotNetZip时,ZipFile.Read(path)每当阅读带有这些问题之一的zip文件时,调用都会被废弃.这意味着我甚至无法尝试过滤掉它.
using (ZipFile zip = ZipFile.Read(path))
{
...
}
Run Code Online (Sandbox Code Playgroud)
处理阅读这些文件的最佳方法是什么?
更新:
来自此处的示例拉链:https: //github.com/MonoReports/MonoReports/zipball/master
重复:https: //github.com/MonoReports/MonoReports/tree/master/src/MonoReports.Model/DataSourceType.cs https://github.com/MonoReports/MonoReports/tree/master/src/MonoReports.Model/DatasourceType的.cs
以下是有关异常的更多详细信息:
Ionic.Zip.ZipException:无法读取它作为ZipFile
---> System.ArgumentException:已添加具有相同键的>项目. System.ChrowArgumentException
(ExceptionResource资源)
at System.Collections.Generic.Dictionary 2.Add(TKey key,TValue value) at Ionic.Zip.ZipFile.ReadCentralDirectory(ZipFile zf) at Ionic.Zip.ZipFile.ReadIntoInstance(ZipFile) ZF)2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary
解析度:
根据@ Cheeso的建议,我可以从流中读取所有内容,避免重复内容和路径问题:
//using (ZipFile zip = ZipFile.Read(path))
using (ZipInputStream stream = new ZipInputStream(path))
{
ZipEntry e;
while( (e = stream.GetNextEntry()) != null )
//foreach( ZipEntry e in zip)
{ …Run Code Online (Sandbox Code Playgroud)