Deployment Tools Foundation
Working with Cabinet Files
Development Guide > Cabinet Files

Creating a cabinet

    CabInfo cabInfo = new CabInfo("package.cab");
    cabInfo.Pack("D:\\FilesToCompress");

1.  Create a new CabInfo instance referring to the (future) location of the .cab file.

2.  Compress files:


Listing a cabinet

    CabInfo cabInfo = new CabInfo("package.cab");
    foreach (CabFileInfo fileInfo in cabInfo.GetFiles())
        Console.WriteLine(fileInfo.Name + "\t" + fileInfo.Length);

1.  Create a new CabInfo instance referring to the location of the .cab file.

2.  Enumerate files returned by the GetFiles method.


Extracting a cabinet

    CabInfo cabInfo = new CabInfo("package.cab");
    cabInfo.Unpack("D:\\ExtractedFiles");

1.  Create a new CabInfo instance referring to the location of the .cab file.

2.  Extract files:


Getting progress

Most cabinet operation methods have an overload that allows you to specify a event handler for receiving archive progress events. The XPack sample demonstrates use of the callback to report detailed progress to the console.


Stream-based compression

The CabEngine class contains static methods for performing compression/decompression operations directly on any kind of Stream. However these methods are more difficult to use, since the caller must implement a stream context that provides the file metadata which would otherwise have been provided by the filesystem. The CabInfo class uses the CabEngine class with FileStreams to provide the more traditional file-based interface.


See also: