SevenZipSharp: Extractor (Asynchronous)

1. Import the SevenZip namespace in your namespace first.

  1. using SevenZip;

2. Create object from SevenZipExtractor with a path for the 7z file and the password for encrypted 7z, if the 7z file was encrypted.

  1. SevenZipExtractor se = new SevenZipExtractor(@"C:\Users\Thada\Desktop\Test7Zip\test.7z", "passwordhere");

PS. add @ sign in front of path string.

3. Use BeginExtractArchive method to compress files and encrypt with a password

  1. BeginCompressFilesEncrypted( Path of extracted files);

  1. se.BeginExtractArchive(@"C:\Users\Thada\Desktop\Test7Zip\Extracted\");

4. Done!! But also not completely. The method that we are using is asynchronous,

There are 5 events:

· Extracting

· ExtractionFinished << Focus on this

· FileExists

· FileExtractionFinished

· FileExtractionStarted

5. We have to embed the method for the event. So, start typing your object’s name and follow by dot with ExtractionFinished.

Note: try to use intellisense to help you coding. When you are typing, there will be a list box of names that are partial match of your typing. Then click tab or spacebar button, it will autocomplete for you.

6. Type operation += and then click tab twice. Visual Studio will complete the statement and create a method for you. You will get something like these.

  1. se.ExtractionFinished += new EventHandler<EventArgs>(se_ExtractionFinished);

  1. void se_ExtractionFinished(object sender, EventArgs e)
  2. {
  3.     Console.WriteLine("…Extraction Finished");
  4. }

7. Add any statement you want in the method. After the extraction finished, it will call this method automatically.

Reference:

Vadim, M. (2010, 8 27). SevenZipSharp Documentation. Retrieved 1 4, 2011, from http://sevenzipsharp.codeplex.com/releases/51254/download/145909