3

I am writing a Winform application in .NET 3.5, and I need unzip a .rar or .zip file.
I found many things, but I didn't found none 3rd party. I couldn't change to .NET 4 or .NET 4.5.

Thank you for your help. Horbert

Horbert
  • 371
  • 3
  • 6
  • 14
  • possible duplicate of [How to Unzip all .Zip file from Folder using C# 4.0 and without using any OpenSource Dll?](http://stackoverflow.com/questions/16052877/how-to-unzip-all-zip-file-from-folder-using-c-sharp-4-0-and-without-using-any-o) – H H May 27 '13 at 18:21
  • Has been asked many times before. – H H May 27 '13 at 18:21

4 Answers4

4

If you only need to uncompress a zip file, you can achieve it without adding an external third-party library.

All you need to to is Add a reference to Microsoft Shell controls and Automation from the COM tab in the Reference Manager in Visual Studio.

private static void Unzip(String sourceFile,String destination) 
{
    Shell32.ShellClass sc = new Shell32.ShellClass();
    Shell32.Folder SrcFlder = sc.NameSpace(sourceFile);
    Shell32.Folder DestFlder = sc.NameSpace(destination);
    Shell32.FolderItems items = SrcFlder.Items();
    DestFlder.CopyHere(items, 20);          
}

With this, you don't have to distribute any additional dll file with your application.

arturn
  • 725
  • 2
  • 11
  • 25
  • Hi @arturn, I am getting the following exception in my WPF windows application pointing .NET 3.5. Any help would be appreciated. Unable to cast COM object of type 'Shell32.ShellClass' to interface type 'Shell32.IShellDispatch6'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{286E6F1B-7113-4355-9562-96B7E9D64C54}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). P.S: I have my app configured with the [STAThread] attribute. – Arjun Natarajan Aug 25 '20 at 09:52
3

How about http://www.codeproject.com/Articles/645214/Compress-Decompress-Zip-Files-w

Not the best solution, but works well if you need basic zip/unzip functionality.

Disclaimer: I'm the author of the article.

ace
  • 201
  • 2
  • 2
2

The .NET framework doesn't support .RAR files, and didn't have support for Zip files until .NET 4.5.

If you want to support .ZIP (or .RAR) in .NET 3.5, you'll need a third party solution. The DotNetZip library, for example, supports .NET 3.5, and is fully functional for handling of .ZIP files.

There are commercial products which support RAR, such as Chilkat RAR.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
1

Actually, .NET 3.5 does .zip files using the DeflateStream. You have to handle the headers yourself, but PKWare has published the specification and you can create structs and use Streams.

There is no need of third party code…but, you do have to approach it in a more traditional, old school manner. They don't exactly unzip themselves.