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


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

Let's say you're building an app that needs access to file metadata, maybe picture metadata? Location, F-Stop, Camera? Or music metadata? Video?

Rob Sanders shows us how...

Extracting File Metadata with C# and the .NET Framework


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?

Introducing the Windows API Code Pack

Thankfully, someone has already done the leg work for us, and it has culminated in the extremely useful Windows API Code Pack, the latest release being available via this link.

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:..



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

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:

  • Windows 7 Taskbar
    • Jump Lists, Icon Overlay, Progress Bar, Tabbed Thumbnails, and Thumbnail Toolbars
  • Windows Shell
    • Windows 7 Libraries
    • Windows Shell Search API support
    • Explorer Browser Control
    • A hierarchy of Shell Namespace entities
    • Windows Shell property system
    • Drag and Drop for Shell Objects
    • Windows Vista and Windows 7 Common File Dialogs, including custom controls
    • Known Folders and non-file system containers
    • Shell Object Watcher
    • Shell Extensions API support
  • DirectX
    • Direct3D 11.0, Direct3D 10.1/10.0, DXGI 1.0/1.1, Direct2D 1.0, DirectWrite, Windows Imaging Component (WIC) APIs
  • Windows Vista and Windows 7 Task Dialogs
  • Sensor Platform APIs
  • Extended Linguistic Services APIs
  • Power Management APIs
  • Application Restart and Recovery APIs
  • Network List Manager APIs
  • Command Link control and System defined Shell icons
What’s New in this update (v1.1):
The enhancements in this update of Code Pack are:
  • Many FxCop violations and PREfast warnings have been addressed
  • Bug fixes across various features and samples
    • Includes many API improvements
  • New features
    • Shell Object Watcher
    • Preview Handler APIs
    • Thumbnail Handler APIs
  • New samples for the new features
  • Visual Studio 2010 compliance
  • Initial xUnit test coverage
  • String localization
  • Signed assemblies

Here's a snap of the Samples (via WinDirStat)


Since we're focusing on properties, here's a snip of them from the doc's;


And specifically, Photo properties;


Yeah, wow. And all this is just the tip of the Code Pack archive.

BTW, I'm on Windows 8.1 and VS 2013 and the code samples seemed to run and work just fine...


Image Credit: Global Nerdy - Windows API Code Pack for .NET Framework Released

The Discussion

  • User profile image

    That's super awesome! I'm actually working on some code to consolidate all my images from various drives in to a single location, then sending them to flickr...cuz 1TB!

    If you're interested i'm actually creating a hash of the image contents, I wrote some functions for powershell, that i'm working on flipping over to c# since i'm moving all my powershell dev to c#.

    the function is get-bitmaphash

    it uses system.drawing to load the image into memory then I just use cryptoserviceprovider to compute the hash from the memory stream.

    There is some other stuff that will pull gps data from the exif tags and give you coordinates and such.


  • User profile image

    @jspatton: Your code look very interesting, thanks to share thisCool

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.