OpenMcdf 3.0.3

GitHub Actions CodeQL OpenMcdf NuGet OpenMcdf.Ole NuGet NuGet Downloads

OpenMcdf

OpenMcdf is a fully .NET / C# library to manipulate Compound File Binary File Format files, also known as Structured Storage.

Compound files include multiple streams of information (document summary, user data) in a single container, and is used as the bases for many different file formats:

  • Advanced Authoring Format (.aaf)
  • Microsoft Office (.doc, .xls, .ppt)
  • Outlook messages (.msg)
  • Visual Studio Solution Options (.suo)
  • Windows thumbnails cache files (Thumbs.db)

OpenMcdf v3 has a rewritten API and supports:

  • An idiomatic dotnet API and exception hierarchy
  • Fast and efficient enumeration and manipulation of storages and streams
  • File sizes up to 16 TB (using major format version 4 with 4096 byte sectors)
  • Transactions (i.e. commit and/or revert)
  • Consolidation (i.e. reclamation of space by removing free sectors)
  • Nullable attributes

Limitations

  • Limited error tolerance/recovery
  • No support for single writer, multiple readers
  • No support for red-black tree balancing

Directory entries are stored in a perfect binary tree where the entries are sorted but the tree is not balanced. i.e. the tree is "all-black", which is a valid red-black tree but has suboptimal performance for traversing large trees (though still considerably faster than some other clients).

Clients such as LibreOffice create trees with red-violations, which OpenMcdf is tolerant to reading and writing. Files with balanced red-black trees such as those created by Microsoft implementations will currently become unbalanced upon adding or removing directory entries. Fortunately, since other clients are also tolerant of trees that are either unbalanced or have red-violations, this should not be a major issue. The Wine implementation also has the same limitation.

Getting started

To create a new compound file:

byte[] b = new byte[10000];

using var root = RootStorage.Create("test.cfb");
using CfbStream stream = root.CreateStream("MyStream");
stream.Write(b, 0, b.Length);

To open an Excel workbook (.xls) and access its main data stream:

using var root = RootStorage.OpenRead("report.xls");
using CfbStream workbookStream = root.OpenStream("Workbook");

To create or delete storages and streams:

using var root = RootStorage.Create("test.cfb");
root.CreateStorage("MyStorage");
root.CreateStream("MyStream");
root.Delete("MyStream");

For transacted storages, changes can either be committed or reverted:

using var root = RootStorage.Create("test.cfb", StorageModeFlags.Transacted);
root.Commit();
//
root.Revert();

A root storage can be consolidated to reduce its on-disk size:

root.Flush(consolidate: true);

Object Linking and Embedding (OLE) Property Set Data Structures

Support for reading and writing OLE Properties is available via the OpenMcdf.Ole package. However, the API is experimental and subject to change.

OlePropertiesContainer co = new(stream);
foreach (OleProperty prop in co.Properties)
{
  ...
}

OpenMcdf runs happily on the Mono platform and multi-targets netstandard2.0 and net8.0 to maximize client compatibility and support modern dotnet features.

Showing the top 20 packages that depend on OpenMcdf.

Packages Downloads
MsgReader
Read Outlook MSG and EML files without using Outlook. The MSGReader supports MSG E-Mail (also signed), Contact, Appointment, Task, Sticky notes and Contact files. The EML reader supports MIME 1.0 encoded files
2
MsgReader
Read Outlook MSG and EML files without using Outlook. The MSGReader supports MSG E-Mail (also signed), Contact, Appointment, Task, Sticky notes and Contact files. The EML reader supports MIME 1.0 encoded files
3
MsgReader
Read Outlook MSG and EML files without using Outlook. The MSGReader supports MSG E-Mail (also signed), Contact, Appointment, Task, Sticky notes and Contact files. The EML reader supports MIME 1.0 encoded files.
2
MsgReader
Read Outlook MSG and EML files without using Outlook. The MSGReader supports MSG E-Mail (also signed), Contact, Appointment, Task, Sticky notes and Contact files. The EML reader supports MIME 1.0 encoded files.
6
MsgReader
Read Outlook MSG and EML files without using Outlook. The MSGReader supports MSG E-Mail (also signed), Contact, Appointment, Task, Sticky notes and Contact files. The EML reader supports MIME 1.0 encoded files.
7

.NET 8.0

  • No dependencies.

.NET Standard 2.0

Version Downloads Last updated
3.0.3 1 09/06/2025
3.0.2 2 08/29/2025
3.0.1 8 06/29/2025
3.0.0 6 06/08/2025
3.0.0-preview.5 6 06/08/2025
3.0.0-preview.4 7 06/08/2025
3.0.0-preview.3 5 06/09/2025
3.0.0-preview.2 7 06/08/2025
2.4.1 7 06/08/2025
2.4.0 8 06/08/2025
2.3.1 7 06/08/2025
2.3.0 7 06/08/2025
2.2.1.12 6 06/08/2025
2.2.1.9 7 06/08/2025
2.2.1.6 6 06/08/2025
2.2.1.5 7 06/08/2025
2.2.1.4 6 06/08/2025
2.2.1.3 6 06/08/2025
2.2.1.2 7 06/08/2025
2.2.0.1 6 06/08/2025
2.1.6.28924 5 06/08/2025
2.1.5.22659 6 06/08/2025
2.1.4.23498 6 06/08/2025
2.1.3.34730 7 06/08/2025
2.1.3.34720 6 06/08/2025
2.1.2.1274 5 06/09/2025
2.1.0.33051 6 06/08/2025
2.0.5739.40493 7 06/08/2025
1.5.4.22637 7 06/08/2025