Last active
June 16, 2025 16:11
Extract Specific Files from ZIP Archives in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Aspose.Zip; | |
// Extract specific file by name | |
class Program | |
{ | |
static void Main() | |
{ | |
// Define path for the working directories. | |
string zipPath = "sample.zip"; | |
string extractPath = "data"; | |
string fileName = "sample.txt"; | |
// Load the source ZIP file by initializing an instance of the Archive class. | |
using (var archive = new Archive(zipPath)) | |
{ | |
// Iterate through the entries of the ZIP file. | |
foreach (var entry in archive.Entries) | |
{ | |
if (entry.Name == fileName) | |
{ | |
// Invoke the Extract method to extract the specified file. | |
entry.Extract(Path.Combine(extractPath, entry.Name)); | |
Console.WriteLine($"Extracted: {entry.Name}"); | |
break; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment