有没有办法在不解压缩的情况下打开 zip 文件中的文件 (c#)

Is there a way to open files in a zip file without decompressing (c#)

我的问题很简单,我有一个包含很多文件的 zip 文件(混合:pdf png 和 txt)。我需要编写一个 C# 程序来查看 zip 文件,循环遍历并仅打开 png 文件而不解压缩。我找到的所有解决方案都包括解压缩整个 zip 文件,这只会使目标文件夹更重。 最简单的方法是什么?

非常感谢,

乔什。

我相信你可以使用 System.IO.Compression 库...

程序集:System.IO.Compression.ZipFile.dll

类似下面的内容...

using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
    foreach (ZipArchiveEntry entry in archive.Entries)
    {
        if (entry.FullName.EndsWith(".png", StringComparison.OrdinalIgnoreCase))
        {
            entry.ExtractToFile(destinationPath);
        }
    }
}