1. Import the SevenZip namespace in your namespace first.
- 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.
- 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
- BeginCompressFilesEncrypted( Path of extracted files);
- 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.
- se.ExtractionFinished += new EventHandler<EventArgs>(se_ExtractionFinished);
- void se_ExtractionFinished(object sender, EventArgs e)
- {
- Console.WriteLine("…Extraction Finished");
- }
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