I’ve been trying to figure out how to store some metadata information on file system. One way to do this, is using Structured Storage. You’ve probably seen this in action, if not, you can open file Properties and select the Summary (Details in Windows Vista) tab.

StructuredStorage

Unfortunately, there’s no managed way to access this data in .NET environment, and there’s no resource on how to call this unmanaged API in .NET, so I decided to write a wrapper around already existing API in OLE32.Dll and here it is.

There are some limitation on what you can do with this and where you can use it. Basically, this metadata is only available on NTFS file system, meaning if you manipulate this metadata on a file and move it to a FAT32 file system, all the data is lost (of course Windows will notify you about this). Furthurmore, you have Microsoft Office file formats, which have build-in metadata storage capability. The good thing is if you move a office file to a FAT32 filesystem, the already existing metadata will not perish.

So, provided class here wraps around StgOpenStorageEx method in OLE32. The StgOpenStorageEx method works with two interfaces :

  • The IPropertyStorage interface which manages the persistent properties of a single property set.
  • The IPropertySetStorage that opens, creates and deletes the property set storages that support instances of the IPropertyStorage interface.

The implementation here only reads and writes the data, but should you need a more elegant solution, e.g. deleting a set, you should have no problem finding your way out.

~ You can download the file here.

Updated : Use my sky drive folder to download the attachment.