5

how to find list of files inside zip file without unzipping it in c#.

Kris van der Mast
  • 16,128
  • 8
  • 38
  • 60
Niraj Choubey
  • 3,770
  • 18
  • 57
  • 92
  • possible duplicate of [How do I ZIP a file in C#, using no 3rd-party APIs?](http://stackoverflow.com/questions/940582/how-do-i-zip-a-file-in-c-using-no-3rd-party-apis) – egrunin Jul 03 '10 at 18:55

2 Answers2

8

With sharpziplib:

ZipInputStream zip = new ZipInputStream(File.OpenRead(path));
ZipEntry item;
while ((item = zip.GetNextEntry()) != null)
{
    Console.WriteLine(item.Name);
}
Marc Gravell
  • 976,458
  • 251
  • 2,474
  • 2,830
  • is it possible without sharpziplib. – Niraj Choubey Jul 03 '10 at 07:39
  • @Niraj Choubey: yes, with some other ZIP library (like http://dotnetzip.codeplex.com/) ..... or you have to re-create the whole ZIP code yourself just to peek inside the ZIP file.... – marc_s Jul 03 '10 at 07:55
  • maybe the `System.IO` will support ZIP archives natively in a future version of the .NET framework - see http://blogs.msdn.com/b/bclteam/archive/2010/06/28/working-with-zip-files-in-net.aspx – marc_s Jul 04 '10 at 07:19
2

There is a simple way to do this with sharpziplib :

        using (var zipFile = new ZipFile(@"C:\Test.zip"))
        {
            foreach (ZipEntry entry in zipFile)
            {
                Console.WriteLine(entry.Name);
            }
        }