Looks like no built-in Library/API in C# to unzip a zip file. I am looking for a free (better open source) library/API which could work with .Net 3.5 + VSTS 2008 + C# to unzip a zip file and extract all files into a specific folder.
Any recommended library/API or samples?
The GPL
http://www.icsharpcode.net/OpenSource/SharpZipLib/
OR the less restrictive Ms-PL
http://www.codeplex.com/DotNetZip
To complete this answer the .net framework has ZipPackage I had less success with it.
If all you want to do is unzip the contents of a file to a folder, and you know you'll only be running on Windows, you can use the Windows Shell object. I've used dynamic
from Framework 4.0 in this example, but you can achieve the same results using Type.InvokeMember
.
dynamic shellApplication = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"));
dynamic compressedFolderContents = shellApplication.NameSpace(sourceFile).Items;
dynamic destinationFolder = shellApplication.NameSpace(destinationPath);
destinationFolder.CopyHere(compressedFolderContents);
You can use FILEOP_FLAGS to control behaviour of the CopyHere
method.
DotNetZip is easy to use. Here's an unzip sample
using (var zip = Ionic.Zip.ZipFile.Read("archive.zip"))
{
zip.ExtractAll("unpack-directory");
}
If you have more complex needs, like you want to pick-and-choose which entries to extract, or if there are passwords, or if you want to control the pathnames of the extracted files, or etc etc etc, there are lots of options. Check the help file for more examples.
DotNetZip is free and open source.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With