Tag Archives: Shell32
The .NET Framework didn’t have an easy way for developers to unzip files resulting to a lot of people having to use third party libraries to achieve that functionality. This was until the .NET Framework 4.5 was released which had a new class called ZipFile that simplified the process of unzipping files..
But since targeting the .NET Framework 4.5 might not be ideal in many cases, mainly because its adaptation rate is still fairly low I will demostrate another way to unzip .zip files with the use of Shell32.
Firstly you will need to reference in your project the COM library called Microsoft Shell Controls And Automation (Interop.Shell32.dll) in order to be able to access the Shell32 namespace.
The method below is a simple example that takes two parameters. The .zip file location and the folder destination where the files will be extracted to.
public static void UnZip(string zipFile, string folderPath)
throw new FileNotFoundException();
Shell32.Shell objShell = new Shell32.Shell();
Shell32.Folder destinationFolder = objShell.NameSpace(folderPath);
Shell32.Folder sourceFile = objShell.NameSpace(zipFile);
foreach (var file in sourceFile.Items())
destinationFolder.CopyHere(file, 4 | 16);
The usage is fairly simple:
UnZip(@"C:\myzipfile.zip", @"C:\my destination folder");