从 ZipFile 中检索文件名

coi*_*ird 2 c# zip ionic-zip

正如标题所示,我需要从 zip 文件中读取文件名。我将把名称输入一个二维字符串数组(以及其他数据)。这是我想做的事情的一个开始示例。

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;
}
Run Code Online (Sandbox Code Playgroud)

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

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

Van*_*nna 5

您需要使用该类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));
        }
    } 
Run Code Online (Sandbox Code Playgroud)