Home > C# > How to create a CAB (cabinet) file using C#

How to create a CAB (cabinet) file using C#

At present we do not have classes in .NET that enable us to create CAB (cabinet) files, hence we has other third party libraries and toolsets that provide their custom classes, one such is Windows Installer XML (WiX) toolset (http://wix.sourceforge.net) which is distributed with a collection of dlls as part of its SDK and best of all is that this is developed by Microsoft and we have good support for WiX users.

In your .NET project add references to the following DLLs:
Microsoft.Deployment.Compression.dll
Microsoft.Deployment.Compression.Cab.dll

And we will be using this library (Microsoft.Deployment.Compression.Cab) for creating CAB (cabinet) files.

using Microsoft.Deployment.Compression.Cab;

In our example we will see how to add individual files to the CAB file and how to add a folder (directory) to the CAB file and finally how to extract (unpack) the CAB file.

// CREATING CAB FILE BY ADDING LIST OF FILES
CabInfo cab = new CabInfo(@"C:\testarchive1.cab");
List files = new List();
files.Add(@"C:\test1.txt");
files.Add(@"C:\test2.txt");
files.Add(@"C:\test3.txt");
cab.PackFiles(null,files,null);

// CREATING CAB FILE BY ADDING FOLDER (WITH SUB-FOLDERS) USING MINIMUM COMPRESSION
cab = new CabInfo(@"C:\testarchive2.cab");
cab.Pack(@"C:\Balaji", true, Microsoft.Deployment.Compression.CompressionLevel.Min, null);

// EXTRACTING (UNPACKING) FILES FROM CAB FILE
cab = new CabInfo(@"C:\testarchive1.cab");
cab.Unpack(@"C:\ArchieveDir");
Advertisements
  1. April 6, 2011 at 1:49 AM

    How to create another type of zip archive like .tar,.rar and .tar.gz

  2. April 6, 2011 at 1:50 AM

    How to create another type of zip archive like .tar,.rar and .tar.gz etc

  3. Powerful pyramid
    June 14, 2011 at 5:15 AM

    I really like your writing style, excellent information, regards for putting up : D.

  4. August 8, 2011 at 5:42 PM

    I just added your website on my blogroll. I may come back later on to check out updates. Excellent information!

  5. August 10, 2011 at 7:49 AM

    I just added your website on my blogroll. Really enjoyed reading through. Excellent information!

  6. August 10, 2011 at 10:26 PM

    Great finding the time go over this, I find myself solidly relating to this as well as real love looking over a little more about this specific concept. However, if chance, like you obtain competence, can you ideas improving your net with the help of longer specifics? This can be very for my vision.

  7. February 22, 2012 at 4:32 AM

    How to create a CAB (cabinet) file using C# Code Support I was suggested this website by my cousin. I’m not sure whether this post is written by him as no one else know such detailed about my trouble. You’re wonderful! Thanks! your article about How to create a CAB (cabinet) file using C# Code Support Best Regards Cassetta Justin

  8. February 24, 2012 at 8:59 AM

    An gripping language is worth scuttlebutt. I think that you should create more on this topic, it strength not be a prejudice soul but mostly group are not enough to speak on such topics. To the next. Cheers like your How to create a CAB (cabinet) file using C# Code Support.

  9. February 25, 2012 at 5:19 AM

    How to create a CAB (cabinet) file using C# Code Support I was suggested this web site by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my problem. You are amazing! Thanks! your article about How to create a CAB (cabinet) file using C# Code Support Best Regards Schaad Cindy

  10. March 1, 2012 at 5:46 AM

    Thank you very much! After spending months searching for an alternative to CabLib, this short post came to my rescue.

  11. March 3, 2012 at 12:12 PM

    Either you run the day or the day runs you. Jim Rohn

  12. March 4, 2012 at 3:27 PM

    Can I just say what a relief to discover someone who actually knows what theyre talking about on the on the web. You definitely know how to bring an issue to light and make it worthwhile. Lots more people must look at this and understand this side of the story. I can not believe you’re not more well-known given that you definitely have the gift.

  13. March 5, 2012 at 11:33 AM

    It’s hard to find knowledgeable people on this topic, but you sound like you know what you’re talking about! Thanks

  14. May 18, 2012 at 12:39 AM

    Excellent post at How to create a CAB (cabinet) file using C# Code Support. I was checking continuously this blog and I am impressed! Very useful info particularly the last part 🙂 I care for such info a lot. I was looking for this certain information for a long time. Thank you and good luck.

  1. No trackbacks yet.

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: