To zip a folder and all its contents using built-in C# libraries, use the
System.IO.Compression.ZipFile class, available in .NET Framework 4.5+ and .NET Core.
Example: Zip an Entire Folder
using System.IO.Compression;
public class ZipHelper
{
public static void ZipFolder(string sourceFolderPath, string destinationZipPath)
{
// Overwrite if ZIP already exists
if (File.Exists(destinationZipPath))
File.Delete(destinationZipPath);
ZipFile.CreateFromDirectory(sourceFolderPath, destinationZipPath, CompressionLevel.Optimal, includeBaseDirectory: true);
}
}
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
To zip a folder and all its contents using built-in C# libraries, use the
System.IO.Compression.ZipFileclass, available in .NET Framework 4.5+ and .NET Core.Example: Zip an Entire Folder
Usage
Parameters Explained
sourceFolderPathdestinationZipPathCompressionLevel.OptimalincludeBaseDirectory: trueNotes
System.IO.CompressionandSystem.IO.Compression.FileSystem.