0

I want to create content of a zip file in treeview, but my problem is how to recognize the content of zip file is file or directory without extract the files and then add them to tree?

would you mind help me in solving this?

Amir
  • 1,919
  • 8
  • 53
  • 105

1 Answers1

2

This functionality is available out of the box in .Net Framework 4.5 and later. You have to use this library:

using System.IO.Compression;

And then you'll be able to do this:

string zipPath = @"c:\example\start.zip";
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
    foreach (ZipArchiveEntry entry in archive.Entries)
    {
        if (entry.FullName.EndsWith('\'))
            Console.WriteLine($"{entry.FullName} is a directory.");
        else
            Console.WriteLine($"{entry.FullName} is a file.");
    }
} 

See here for more details:

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

Sepehr Samiei
  • 382
  • 1
  • 6