2017-08-10 34 views
1

就像标题所说,我需要从zip文件中读取文件的名称。我将把这些名称提供给一个2D字符串数组(以及其他数据)。这是我想要做的一个开始的例子。从ZipFile中检索文件名

private String[,] ArrayFiller(ZipFile MyZip) 
{ 
    int count = 0; 
    ZipFile zipfile = ZipFile.Read(); 
    int zipSize = MyZip.Count; 
    string[,] MyArr = new string[zipSize, zipSize]; 

    foreach (ZipEntry e in zipfile.EntriesSorted) 
    { 
     //dbcrArr[count,count] = e; -adds the file, but I need title 
    } 
    return MyArr; 
} 

我敢肯定我错过了简单的东西,但我似乎无法在ZipFile类中找到“文件名”属性。导入的软件包称为Ionic.Zip。

也许它是某种压缩对象的属性?

+0

是的,那绝对是错误的文档。 – hvd

+0

@ hvd哎呀。我会更新它。 – coinbird

回答

2

您需要使用ZipArchive类。从MSDN

using (ZipArchive archive = ZipFile.OpenRead(zipPath)) 
    { 
     foreach (ZipArchiveEntry entry in archive.Entries) 
     { 
      Console.WriteLine(entry.FullName); 
      //entry.ExtractToFile(Path.Combine(destFolder, entry.FullName)); 
     } 
    } 
+0

所以它看起来像你将ZipFile对象转换为ZipArchive?保留我现在拥有的东西,只是将其转换为ZipArchive并在文件“entry”中使用.FullName方法? – coinbird

3

你可能有更多的运气与ZipArchive类。

using (ZipArchive archive = ZipFile.OpenRead(zipPath)) 
{ 
    foreach (ZipArchiveEntry entry in archive.Entries) 
    { 
      // The file name is entry.FullName 
    } 
}