The following example shows how to open a zip archive and extract all .txt files to a folder
suggest changeusing System;
using System.IO;
using System.IO.Compression;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string zipPath = @"c:\example\start.zip";
string extractPath = @"c:\example\extract";
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
{
entry.ExtractToFile(Path.Combine(extractPath, entry.FullName));
}
}
}
}
}
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents