小编gam*_*eld的帖子

如何使用太长/重复的路径解压缩ZipFile

在Windows中解压缩文件时,我偶尔会遇到路径问题

  1. 这对于Windows来说太长了(但在创建该文件的原始操作系统中没问题).
  2. 由于不区分大小写,它们是"重复的"

使用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)

c# zipfile dotnetzip

10
推荐指数
2
解决办法
7424
查看次数

标签 统计

c# ×1

dotnetzip ×1

zipfile ×1