Something that should be in everyone's pack, the Windows API Code Pack

Description

Today's Windows Wednesday project is one that's maybe not earth shattering or beyond wild, but could end up helping more of you than not. Helping you take advantage of the Windows OS in a much simpler, easier and Managed friendly way

Over the weekend, I decided to try and import image metadata using C# and the .NET Framework. Aside from “normal” file attributes such as date modified and size, the Windows Explorer (shell) provides extended file property information which can be quite valuable.

The challenge was how to extract this information, given that the .NET Framework has somewhat limited support for this type of extraction? Read on to find out how.

...

In my specific scenario, I want access to extended properties which relate to photos, e.g. ISO Speed, F-stop, Focal Length, Dimensions and so forth. Each property has an identifier which can be used to retrieve the associated property data. You can do this from .NET for some information, as seen here

...

Therefore you can obtain more information like this by using Win32 interop and invoking shell calls directly from C#/.NET, but this can be time consuming, not to mention laborious as you have to track down the correct Win32 API interfaces and property item IDs to use. Surely there’s an easier way?

The Pack itself contains documentation, samples, pre-compiled binaries and the source code for the binaries.

...

Retrieving Extended Property Data

One of the best features of the Pack must be the fact that someone has gone and mapped all the extended property values to strongly typed definitions, which saves us a lot of time and effort.

For example, given the fully qualified path and file name of a photo, we could retrieve extended file information (such as Camera Manufacturer and Camera Model) by using the following code:

...

Using the Pack

Based on the above, it was easy as pie to extract extended photo property data. I wrote a small utility to demonstrate how straight forward it is to extract the required data. You need to reference two assemblies from the pack – Microsoft.WindowsAPICodePack.dll andMicrosoft.WindowsAPICodePack.Shell.dll.

Here’s a complete dump of the code I used:..

...

Summary

There’s obviously a lot more to this Pack than an abstraction of the Windows Shell API. I might do some more exploration at a later time, but I felt this article might be handy for those out there who needed an easier solution for extracting extended file property data. Enjoy.

Windows® API Code Pack for Microsoft® .NET Framework provides a source code library that can be used to access some features of Windows 7 and Windows Vista from managed code. These Windows features are not available to developers today in the .NET Framework.

The individual features supported in this version (v1.1) of the library are: