You can now use the ZipArchive class (System.IO.Compression.ZipArchive), available from .NET 4.5
You have to add System.IO.Compression
as a reference.
Example: Generating a zip of PDF files
using (var fileStream = new FileStream(@"C:\temp\temp.zip", FileMode.CreateNew))
{
using (var archive = new ZipArchive(fileStream, ZipArchiveMode.Create, true))
{
foreach (var creditNumber in creditNumbers)
{
var pdfBytes = GeneratePdf(creditNumber);
var fileName = "credit_" + creditNumber + ".pdf";
var zipArchiveEntry = archive.CreateEntry(fileName, CompressionLevel.Fastest);
using (var zipStream = zipArchiveEntry.Open())
zipStream.Write(pdfBytes, 0, pdfBytes.Length);
}
}
}
}