searchforsolutions

Just another WordPress.com site

C# : Working with .cab (cabinet) files


.NET does not have any classes for creating cabinet files out-of-box, so today I had to look what else is available out there. There are a couple of solutions I found for creating a .cab file from the .NET code. The one that actually worked for me was a library developed by Microsoft(!) as part of their Windows Installer XML (WiX) toolset. This toolset is distributed with a bunch of dlls as part of its SDK. The library that allows to create cabinet files is called Microsoft.Deployment.Compression.Cab and located under <WIX_Installation_Folder>\SDK.

In your project you need to add a reference to the Microsoft.Deployment.Compression.Cab.dll and to Microsoft.Deployment.Compression.dll (located under the same folder and has some base classes for types defined in the Microsoft.Deployment.Compression.Cab).

After doing this you can add files to a cabinet file from .NET with just a couple of line of code:

using Microsoft.Deployment.Compression.Cab;

//create a instance of Microsoft.Deployment.Compression.Cab.CabInfo
//which provides file-based operations on the cabinet file
CabInfo cab = new CabInfo(@”C:\Cabinet1.cab”);

//create a list with files and add them to a cab file
List<string> filesToArchive = new List<string>() { @”C:\file1″, @”C:\file2″ };
cab.PackFiles(null, filesToArchive, null);

//add a folder (including subdirectories) to another cab file with a maximum compression level
cab = new CabInfo(@”C:\Cabinet2.cab”);
cab.Pack(@”C:\folder”, true, Microsoft.Deployment.Compression.CompressionLevel.Max, null);

//unpack a cab file into C:\Unpacked folder
cab.Unpack(@”C:\Unpacked”);

The library has an MSDN style help file located under <WIX_Installation_Folder>\doc\DTFAPI.chm.

Another dll that also comes with WiX toolset SDK is Microsoft.Deployment.Compression.Zip.dll that provides similar functionality for packing and unpacking zip files.

Ref: http://wix.sourceforge.net/

Advertisements

5 responses to “C# : Working with .cab (cabinet) files

  1. Pingback: Homepage

  2. Homepage July 17, 2012 at 5:55 pm

    I genuinely like this weblog internet site, will surely come back once again. Make confident you carry on creating quality content material articles. 810310

  3. Maui Taxi July 22, 2012 at 6:32 pm

    It is not my first time to visit this website, i am browsing this
    web page dailly and take nice information from here every day.

  4. Pingback: essay about education

  5. Mushtaque Nizamani November 26, 2012 at 4:23 pm

    Thank you very much for sharing the useful info.

    Best Regards,
    Mushi (Found & CEO at http://www.evisionas.com)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: