Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve file names from inside ZipFile

Tags:

c#

zip

ionic-zip

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?

like image 798
coinbird Avatar asked May 15 '26 03:05

coinbird


2 Answers

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));
        }
    } 
like image 98
Vanna Avatar answered May 17 '26 16:05

Vanna


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
     }
} 
like image 44
pankee Avatar answered May 17 '26 17:05

pankee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!