I have seen many tutorials on how to compress a single file in c#. But I need to be able to create a normal *.zip file out of more than just one file. Is there anything in .
This can be done by adding a reference to System.IO.Compression and System.IO.Compression.Filesystem.
A sample createZipFile() method may look as following:
public static void createZipFile(string inputfile, string outputfile, CompressionLevel compressionlevel)
{
try
{
using (ZipArchive za = ZipFile.Open(outputfile, ZipArchiveMode.Update))
{
//using the same file name as entry name
za.CreateEntryFromFile(inputfile, inputfile);
}
}
catch (ArgumentException)
{
Console.WriteLine("Invalid input/output file.");
Environment.Exit(-1);
}
}
where
More details about ZipFile Class in MSDN