Showing posts with label Visual Studio 2010. Show all posts
Showing posts with label Visual Studio 2010. Show all posts

Monday, October 14, 2013

How to do 7zip programmatically using C# ?

Dear All,

Some times it may be possible you require to  make zip of  a file or directory.

so here is simple example.

To start it you have to download “SevenZipSharp.dll”, “7z.dll” you can download sdk from http://www.7-zip.org/sdk.html

Once you download sdk copy above 2 DLL in your project bin folder.

Now write below code which i am writing here

   1:  
   2: public bool CompressFolder(String 
   3: backupFolder)
   4:  
   5: {
   6:  
   7: try
   8:  
   9: {
  10:  
  11: SevenZipCompressor sz = new SevenZipCompressor(); 
  12:  
  13: SevenZip.SevenZipCompressor.SetLibraryPath(DLLPath);
  14:  
  15: sz.CompressionLevel = 
  16: CompressionLevel.Ultra;
  17:  
  18: sz.CompressionMode = 
  19: CompressionMode.Create;
  20:  
  21: sz.CompressionMethod = 
  22: CompressionMethod.Default;
  23:  
  24: sz.FastCompression = 
  25: true;
  26:  
  27: sz.CompressDirectory(backupFolder, BackupPath + "\\" + 
  28: DateTime.Now.Date.ToString("yyyyMMddHHmmss") + 
  29: "_7Zip.7z");
  30:  
  31: Directory.Delete(backupFolder,true);
  32:  
  33: return true;
  34:  
  35: }
  36:  catch (Exception 
  37: ex)
  38:  
  39: {
  40:  
  41: throw ex;
  42:  }



Now let me describe the code to you.


This is function which compress the folder to 7zip what ever pass as a paramter


in this function we have created a sevenzip compressor object


SevenZip.SevenZipCompressor.SetLibraryPath(DLLPath);


in the above line we set the DLLpath which is basically your bin folder path


sz.CompressionLevel = CompressionLevel.Ultra; is compress level which can be different according to your need.


sz.CompressDirectory(backupFolder, BackupPath + "\\" + DateTime.Now.Date.ToString("yyyyMMddHHmmss") + "_7Zip.7z");


above row compress the directory of backupfolder and rename with datetime_7zip.7z


I hope this will help you.


Enjoy 7zip.


Thanks & Best Regards,


Rajat Jaiswla

Tuesday, September 14, 2010

VS-2010 environment

Hello Friends,
It’s great to hear that Microsoft finalized VS-2010 and we can get release mode now.
As you know VS-2010 is based on WPF so lots of changes related to visualization you will a new attractive IDE.
Just see blow image

There is some new project list also as shown in below fig
In this you can find mainly MVC2 application project, Cloud project & more over Share point.

You can find lot of new feature with VS 2010.
Like inherited View State, Routing for SEO related options, parallel LINQ,
For more information you can checkout link http://www.asp.net/learn/whitepapers/aspnet4/default.aspx

Thanks
Rajat
The Adventures of Sherlock Holmes