Compress files and folders using sevenzipsharp and 7-Zip in C# 1

Compress files and folders using sevenzipsharp and 7-Zip in C#

Compressing files using 7-Zip and seven zip sharp (http://sevenzipsharp.codeplex.com/) is really easy.

To get started you would need the 7-Zip DLL (www.7-zip.org/download.html)

namespace Cupofdev
{
 using System;
 using System.IO;
 using SevenZip;

 class Cupofdev
 {
 static void Main(string[] args)
 {
 // Set source and target folders
 string targetFolder = @"E:\CodeDumps";
 string sourceCodeFolder = @"C:\Dev\Clients\cupofdev";
 if (System.IO.Directory.Exists(targetFolder))
 {
 // Specify where 7z.dll DLL is located
 SevenZipCompressor.SetLibraryPath(@"C:\Program Files\7-Zip\7z.dll");
 SevenZipCompressor sevenZipCompressor = new SevenZipCompressor();
 sevenZipCompressor.CompressionLevel = SevenZip.CompressionLevel.Ultra;
 sevenZipCompressor.CompressionMethod = CompressionMethod.Lzma;
 // Compress the directory and save the file in a yyyyMMdd_project-files.7z format (eg. 20141024_project-files.7z
 sevenZipCompressor.CompressDirectory(sourceCodeFolder, Path.Combine(targetFolder, string.Concat(DateTime.Now.ToString("yyyyMMdd"), "_project-files.7z")));
 }
 }
 }
}

Email Newsletter

Missing out on the latest Cupofdev.com developments? Enter your email below to receive future announcements direct to your inbox. An email confirmation will be sent before you will start receiving notifications - please check your spam folder if you don't receive this.