Working with Cabinet Files

Deployment Tools Foundation .NET

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:

  • Easily compress an entire directory with the Pack method.
  • Compress a specific list of exernal and internal filenames with the PackFiles method.
  • Compress a dictionary mapping of internal to external filenames with the PackFileSet method.


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.

  • Each CabFileInfo instance contains metadata about one file.


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:

  • Easily extract all files to a directory with the Unpack method.
  • Easily extract a single file with the UnpackFile method.
  • Extract a specific list of filenames with the UnpackFiles method.
  • Extract a dictionary mapping of internal to external filenames with the UnpackFileSet method.


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: