I like to zip multiple files which are being created dynamically in my web application. Those files should be zipped. For this, i dont want to use any third-party tools. jus
Simple zip file with flat structure:
using System.IO;
using System.IO.Compression;
private static void CreateZipFile(IEnumerable files, string archiveName)
{
using (var stream = File.OpenWrite(archiveName))
using (ZipArchive archive = new ZipArchive(stream, System.IO.Compression.ZipArchiveMode.Create))
{
foreach (var item in files)
{
archive.CreateEntryFromFile(item.FullName, item.Name, CompressionLevel.Optimal);
}
}
}
You need to add reference to System.IO.Compression and System.IO.Compression.FileSystem