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

Viewed 630

my problem is simple, I have a zip file that contains a lot of files (mixed: pdf png and txt). I need to write a C# program that peeks into the zip file, loops through and opens only the png files without decompressing. All the solutions that I find include decompressing the whole zip file which makes the target folder only heavier. What is the easiest way to do it?

thank you very much,

Josh.

1 Answers

i believe you can use the System.IO.Compression library...

Assembly: System.IO.Compression.ZipFile.dll

something like the following...

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