Skip to content

Instantly share code, notes, and snippets.

Extract Specific Files from ZIP Archives in C#
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