---
title: "How can you extract only specific files from a ZIP archive in C#?"  
description: "How can you extract only specific files from a ZIP archive in C#?"  
author: "ICSM Computer"  
published: 2025-05-13  
updated: 2025-05-26  
canonical: https://www.mindstick.com/forum/161614/how-can-you-extract-only-specific-files-from-a-zip-archive-in-c-sharp  
category: "c#"  
tags: ["c#", "file handling"]  
reading_time: 1 minute  

---

# How can you extract only specific files from a ZIP archive in C#?

How can you [extract](https://www.mindstick.com/forum/12883/how-to-extract-sub-string-between-two-string-pattern-using-javascript-jquery) only specific [files](https://www.mindstick.com/articles/23302/the-importance-and-advantage-of-keeping-your-important-files-on-the-cloud) from a [ZIP](https://www.mindstick.com/interview/34182/compress-old-log-files-e-g-zip-after-7-days) [archive](https://answers.mindstick.com/qa/38543/name-the-founder-and-former-director-of-the-national-film-archive-of-india-nfai-pune-who-died-recently-at-the-age-of-82) in C#?

## Replies

### Reply by Anubhav Sharma

To extract only **specific files** from a ZIP archive in C#, you can use the `System.IO.Compression` namespace, particularly `ZipArchive` and `ZipArchiveEntry`.

### Example: Extract Specific Files from ZIP

```cs
using System.IO;
using System.IO.Compression;

public class ZipExtractor
{
    public static void ExtractSelectedFiles(string zipPath, string extractPath, string[] filesToExtract)
    {
        using ZipArchive archive = ZipFile.OpenRead(zipPath);

        foreach (var entry in archive.Entries)
        {
            if (filesToExtract.Contains(entry.FullName))
            {
                string destination = Path.Combine(extractPath, entry.FullName);
                Directory.CreateDirectory(Path.GetDirectoryName(destination)!);
                entry.ExtractToFile(destination, overwrite: true);
            }
        }
    }
}
```

### Usage

```cs
string zipFile = "path/to/archive.zip";
string outputDir = "path/to/output";
string[] filesToExtract = new[]
{
    "documents/readme.txt",
    "images/logo.png"
};

ZipExtractor.ExtractSelectedFiles(zipFile, outputDir, filesToExtract);
```

### Notes

- `entry.FullName` includes any subdirectory path inside the ZIP.
- Be sure the names in `filesToExtract` match the exact path within the ZIP (case-sensitive on some systems).
- You can filter with `entry.Name` if you only care about file names, regardless of folder structure.


---

Original Source: https://www.mindstick.com/forum/161614/how-can-you-extract-only-specific-files-from-a-zip-archive-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
