web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Cup of Dev / Compress files and folders ...

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

Morne Wolfaardt Profile Picture Morne Wolfaardt

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.

Email Address

The post Compress files and folders using sevenzipsharp and 7-Zip in C# appeared first on Cup of dev - A blog for developers by Morne Wolfaardt.


This was originally posted here.

Comments

*This post is locked for comments