Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I list the contents of a .zip folder in c#?

How can I list the contents of a zipped folder in C#? For example how to know how many items are contained within a zipped folder, and what is their name?

like image 774
vbroto Avatar asked Nov 21 '08 03:11

vbroto


People also ask

How do I view the contents of a zip file?

Also, you can use the zip command with the -sf option to view the contents of the . zip file. Additionally, you can view the list of files in the . zip archive using the unzip command with the -l option.

What are the contents of a zip file?

They contain data and files together in one place. But with zipped files, the contents are compressed, which reduces the amount of data used by your computer. Another way to describe ZIP files is as an archive. The archive contains all the compressed files in one location.


2 Answers

.NET 4.5 or newer finally has built-in capability to handle generic zip files with the System.IO.Compression.ZipArchive class (http://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive%28v=vs.110%29.aspx) in assembly System.IO.Compression. No need for any 3rd party library.

string zipPath = @"c:\example\start.zip"; using (ZipArchive archive = ZipFile.OpenRead(zipPath)) {     foreach (ZipArchiveEntry entry in archive.Entries)     {         Console.WriteLine(entry.FullName);     } }  
like image 94
Csaba Toth Avatar answered Sep 19 '22 21:09

Csaba Toth


DotNetZip - Zip file manipulation in .NET languages

DotNetZip is a small, easy-to-use class library for manipulating .zip files. It can enable .NET applications written in VB.NET, C#, any .NET language, to easily create, read, and update zip files.

sample code to read a zip:

using (var zip = ZipFile.Read(PathToZipFolder)) {     int totalEntries = zip.Entries.Count;      foreach (ZipEntry e in zip.Entries)     {         e.FileName ...         e.CompressedSize ...         e.LastModified...     } } 
like image 41
Chris Fulstow Avatar answered Sep 19 '22 21:09

Chris Fulstow