How to compress a folder using 7zip in C#

Here fileDirPath is the path to my folder which has all my files and preferredPath is the path where I want my .zip file to be.

eg:
var fileDirePath = @“C:\Temp”;
var prefferedPath = @“C:\Outputresults.zip”;

private void CreateZipFile(string fileDirPath, string prefferedPath)
        {
            ProcessStartInfo p = new ProcessStartInfo();
            p.FileName = @"C:\Program Files\7-Zip\7z.exe";
            p.Arguments = "a \"" + prefferedPath + "\" \"" + fileDirPath + "\"";
            p.WindowStyle = ProcessWindowStyle.Hidden;
            Process x = Process.Start(p);
            x.WaitForExit();
            return;
        }

Advertisements

Author: Harshani Nawarathna

Sri Lankan woman in Computing

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s