Skip to content

ironfede/openmcdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Actions

OpenMcdf

OpenMcdf is a 100% .NET / C# component that allows developers to manipulate Compound File Binary File Format files (also known as OLE structured storage).

Compound file includes multiple streams of information (document summary, user data) in a single container.

This file format is used under the hood by a lot of applications: all the documents created by Microsoft Office until the 2007 product release are structured storage files. Windows thumbnails cache files (thumbs.db) are compound documents as well as .msg Outlook messages. Visual Studio .suo files (solution options) are compound files and a lot of audio/video editing tools save project file in a compound container (*.aaf files for example).

OpenMcdf supports read/write operations on streams and storages and traversal of structures tree. It supports version 3 and 4 of the specifications, uses lazy loading wherever possible to reduce memory usage and offer an intuitive API to work with structured files.

It's very easy 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);

You can open an existing one, an Excel workbook (.xls) and use its main data stream

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

Adding storage and stream items is just as easy...

using var root = RootStorage.Create("test.cfb");
root.AddStorage("MyStorage");
root.AddStream("MyStream");

...as removing them

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();

If you need to compress a compound file, you can purge its unused space:

root.Flush(consolidate: true);

OLE Properties handling for DocumentSummaryInfo and SummaryInfo streams
is available via extension methods (experimental - API subjected to changes)

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 allow maximum client compatibility.