New to Telerik Document Processing? Start a free 30-day trial
Extract the contents of a zip file to a directory
Updated on Jun 9, 2026
Environment
| Product Version | Product | Author |
|---|---|---|
| 2021.1.325 | RadZipLibrary | Dimitar 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);
}
}
}
}