2

Like the title says, I need to read the names of files from a zip file. I'm going to feed the names into a 2D string array (along with other data). Here's a beginning example of what I'd like to do.

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)
    {
        //otherArr[count,count] = e; -adds the file, but I need title
    }
    return MyArr;
}

I'm sure I'm missing something simple, but I can't seem to find a "file name" property within the ZipFile class. The imported package is called Ionic.Zip.

Maybe it's a property of some kind of zipped object?

coinbird
  • 1,202
  • 4
  • 24
  • 44

2 Answers2

5

You need to use the ZipArchive Class. From MSDN:

    using (ZipArchive archive = ZipFile.OpenRead(zipPath))
    {
        foreach (ZipArchiveEntry entry in archive.Entries)
        {
            Console.WriteLine(entry.FullName);
            //entry.ExtractToFile(Path.Combine(destFolder, entry.FullName));
        }
    } 
Vanna
  • 746
  • 1
  • 7
  • 16
  • So it looks like you're converting the ZipFile object to a ZipArchive? Keep what I have then and just covert it to a ZipArchive and use the .FullName method on the file "entry"? – coinbird Aug 10 '17 at 19:48
3

You might have more luck with the ZipArchive class.

using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
     foreach (ZipArchiveEntry entry in archive.Entries)
     {
          // The file name is entry.FullName
     }
} 
pankee
  • 341
  • 1
  • 2
  • 12