New to Telerik Document ProcessingStart a free 30-day trial

Extract the contents of a zip file to a directory

Updated on Jun 9, 2026

Environment

Product VersionProductAuthor
2021.1.325RadZipLibraryDimitar Karamfilov

Description

This article demonstrates 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 iterates all the files in the archive and extracts each file to the corresponding 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);
                }
            }
        }
    }

See Also