.NET Framework Reading and writing Zip files Listing ZIP contents

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!


This snippet will list all the filenames of a zip archive. The filenames are relative to the zip root.

using (FileStream fs = new FileStream("archive.zip", FileMode.Open))
using (ZipArchive archive = new ZipArchive(fs, ZipArchiveMode.Read))
    for (int i = 0; i < archive.Entries.Count; i++)
        Console.WriteLine($"{i}: {archive.Entries[i]}");

Got any .NET Framework Question?