« Zip up a Folder with PowerShell 3 the Easy Way | Main | How to Easily create an MSI to install your PowerShell modules »

Zip up a Folder with .NET 4.5 and Visual Studio 2012  

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 );


PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (1)

thanks, this tricks is helpful, i have been looking for it all day

December 24, 2012 | Unregistered CommenterSarah

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>