New to Telerik Document ProcessingStart a free 30-day trial

Extract the contents of a zip file to a directory

Updated on Feb 19, 2026
Product VersionProductAuthor
2021.1.325RadZipLibraryDimitar Karamfilov

Description

The example is showing how to extract the contents of a zip file to a directory. The example preserves the file structure inside the archive.

Solution

The following code snippet is iterating all the files in the archive and extracts each file in the respected directory.

csharp

    using (Stream stream = File.Open("test.zip", FileMode.Open))
    {
        using (ZipArchive archive = new ZipArchive(stream))
        {
            string fullName = Directory.CreateDirectory("Extracted Content").FullName;
    
            foreach (ZipArchiveEntry entry in archive.Entries)
            {
                string fullPath = Path.GetFullPath(Path.Combine(fullName, entry.FullName));
                if (Path.GetFileName(fullPath).Length != 0)
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
                    using (Stream fileStream = File.Open(fullPath, FileMode.Create, FileAccess.Write, FileShare.None))
                    {
                        using (Stream entryStream = entry.Open())
                        {
                            entryStream.CopyTo(fileStream);
                        }
                    }
                }
                else
                {
                    Directory.CreateDirectory(fullPath);
                }
            }
        }
    }
In this article
DescriptionSolution
Not finding the help you need?
Contact Support