Zip up a Folder with .NET 4.5 and Visual Studio 2012
Friday, August 17, 2012 at 9:49PM This has never been easier!
First, ensure your project's Target Framework is set to .NET Framework 4.5

Second, add a reference to System.IO.Compression.FileSystem

Finally, call System.IO.Compression.ZipFile.CreateFromDirectory(). There are several overloads for this static method. The example below covers the most typical usage to create a ZIP file from a folder.
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string src_folder = @"D:\stuff";
string destfile = @"D:\stuff.zip";
var compressionLevel = System.IO.Compression.CompressionLevel.Optimal;
bool includebasedir = false;
System.IO.Compression.ZipFile.CreateFromDirectory(src_folder,destfile,compressionLevel, includebasedir );
}
}
}
Reader Comments (1)
thanks, this tricks is helpful, i have been looking for it all day