using System.IO.Compression; ZipInputStream inputStream = new ZipInputStream(File.OpenRead("example.zip")); ZipEntry entry; while ((entry = inputStream.GetNextEntry()) != null) { string directoryPath = Path.GetDirectoryName(entry.Name); string fileName = Path.GetFileName(entry.Name); Directory.CreateDirectory(directoryPath); using (FileStream outputStream = File.Create(directoryPath + "\\" + fileName)) { byte[] buffer = new byte[2048]; int bytesRead; while ((bytesRead = inputStream.Read(buffer, 0, buffer.Length)) > 0) { outputStream.Write(buffer, 0, bytesRead); } } }
using System.IO.Compression; ZipInputStream inputStream = new ZipInputStream(File.OpenRead("example.zip")); ZipEntry entry; while ((entry = inputStream.GetNextEntry()) != null) { if (Path.GetExtension(entry.Name) == ".txt") { using (MemoryStream outputStream = new MemoryStream()) { byte[] buffer = new byte[2048]; int bytesRead; while ((bytesRead = inputStream.Read(buffer, 0, buffer.Length)) > 0) { outputStream.Write(buffer, 0, bytesRead); } string fileContents = Encoding.UTF8.GetString(outputStream.ToArray()); Console.WriteLine(fileContents); } } }Package Library: The ZipInputStream class is part of the System.IO.Compression namespace, which is included in the .NET Framework and .NET Core libraries.