Click here to Skip to main content
Click here to Skip to main content

Metadata from Managed Code

, 18 Sep 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
a custom viewer that would make it easy for everyone to see a picture and view and edit the metadata.

Introduction

My wife and I are into tracking down our ancestors. We have collected family photos from many family members, and hope to share them with all the family. I have scanned in hundreds of photos.

My goal has been to harness the power of metadata to place as much information about each photo into the file itself. That way, when we send someone a copy of the photo, they automatically have all the information we have concerning the contents of the photo.

There are five pieces of metadata that I use. They are Description, Subject, Title, Keywords (Tags), and Rating. These pieces of metadata can be seen through various programs.

You can use Windows Explorer through the Details mode of View. However, trying to get the folder to ‘retain’ the setup for this is impossible. Just about every time I access a folder with pictures, I have to re-select the columns I need to view these five items.

There are many graphics programs such as Picasa, Adobe Photoshop, and others that will allow you to view and edit some of these five items, but I have not found any that will handle them all.

Consequently, I have been working on a custom viewer that would make it easy for everyone to see a picture and view and edit the metadata. But first, I had to be able to read and write the metadata to the image file without affecting the quality of the image.

I have scoured the internet for the means to do that. Most articles only dealt with reading the metadata. The few that attempted to show how to write the metadata were only partially successful. I say ‘only partially successful’ because as any of you who has delved into this subject knows, there are many different protocols used to store the data. There is EXIF, IPTC, XMP to name a few. A single piece of metadata could be stored in each of these formats. So, if you want to insure your information can be read by as many programs as possible, you need to address them all. Adobe comes the closest, but you have to manually handle each protocol.

Only one article that I found seemed to have a simple approach of letting you deal with a single property name, and it handled the messy details of dealing with the various protocols behind the scenes. It was titled “Photo Metadata Policy”. It described accessing the data through the Windows Shell Property system. Using this method allows you to concentrate on the metadata and not have to worry about which schema or schemas it is stored under. The following is a quote from the web page:

Metadata (file properties) for photo files can be stored using multiple metadata schemas, in different data formats, and in different locations within a file. In Windows Vista™, the Microsoft® Windows® Shell provides a built-in property handler for photo file formats, such as JPEG, TIFF, and PNG, to simplify metadata retrieval.

When a piece of metadata is present in different underlying schemas, the built-in property handler determines which value to return.

This sounded great, just what I wanted. Unfortunately, it could only be accessed with C++. I can hardly spell it much less program in it. My language of preference is VB.NET. This sent me back to the internet searching for some managed code to access the Shell properties.

I searched far and wide and found nothing, nada, zilch. Then I noticed a new addition to the Start Page of Visual Studio. Occasionally, I do stop and read the items posted there. Not as often as I should though.

On 09 August of 2009, Microsoft released Windows API Code Pack v1.0 with the following description:

The Windows API Code Pack provides a source code library that can be used to access Windows features from managed code.

I installed the Code Pack and looked through the sample code. In the Samples folder, under PropertiesEditDemo, was just what I needed. It comes in both C# and VB flavors.

I set up a Windows Forms Application project to use that code. It was written as a console project. Re-coding it to a Forms App was the hardest piece of coding I had to do. I created a small class (SHPropertyEdit.vb) to interface between the demo form and the Code Pack. It was nothing exotic and the code should be self-explanatory.

The Code Pack only comes in C#, but, since I don’t need to alter it, that is just fine. After compiling the Code Pack, I moved Microsoft.WindowsAPICodePack.dll and Microsoft.WindowsAPICodePack.Shell.dll to a folder I named DLLs under the SHPropertyEdit folder. After referencing them in SHPropertyEdit and compiling the class, I was ready to go.

The demo form allows for me to locate a media file and perform one of four functions:

  1. Get – get the values for the five properties I am interested in.
  2. Set – the values in the textboxes are written to the file.

  3. Info – returns information about a single property. Type the name of the property in the filter textbox.

  4. Enum – returns the property values for all the properties contained in the file. You can type a single property name in the Filter textbox, or leave the textbox empty and retrieve them all.

I have to admit I have not done testing beyond the five properties I am interested in. But, I did try it out on many different file types: .jpg, .png, .tif, .doc, .wma, .pdf, .xls, .jpg, .dvr-ms, and .mpg.

I am an amateur programmer trying to learn to use .NET and comes up with some useful utilities. If you find anything I have done wrong or could do better, please keep that in mind and keep your criticism constructive.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

rctaubert

United States United States
No Biography provided

Comments and Discussions

 
GeneralRe: SHPropertyEdit not defined Pinmemberrctaubert19-Mar-10 6:08 
GeneralRe: SHPropertyEdit not defined PinmemberMarty_B31-Mar-10 2:07 
GeneralRe: SHPropertyEdit not defined Pinmemberrctaubert31-Mar-10 2:47 
GeneralRe: SHPropertyEdit not defined PinmemberMarty_B31-Mar-10 4:29 
GeneralRe: SHPropertyEdit not defined Pinmemberrctaubert31-Mar-10 6:55 
GeneralRe: SHPropertyEdit not defined PinmemberMarty_B31-Mar-10 7:52 
GeneralRe: SHPropertyEdit not defined PinmemberMarty_B31-Mar-10 8:24 
GeneralRe: SHPropertyEdit not defined Pinmemberrctaubert31-Mar-10 8:58 
GeneralRe: SHPropertyEdit not defined PinmemberMarty_B1-Apr-10 1:20 
GeneralRe: SHPropertyEdit not defined PinmemberMarty_B1-Apr-10 1:31 
GeneralRe: SHPropertyEdit not defined Pinmemberrctaubert1-Apr-10 2:37 
GeneralHelp .. won't open in VS 2005 ! Pinmemberxxxjohn14-Oct-09 6:33 
GeneralRe: Help .. won't open in VS 2005 ! Pinmemberrctaubert14-Oct-09 10:06 
GeneralRe: Help .. won't open in VS 2005 ! Pinmemberredjoy16-Oct-09 13:00 
GeneralRe: Help .. won't open in VS 2005 ! Pinmemberrctaubert17-Oct-09 2:26 
GeneralThanks!!! I have been searching the Net now for four days exactly for this issue. [modified] PinmemberMcAkins10-Oct-09 5:50 
GeneralRe: Thanks!!! I have been searching the Net now for four days exactly for this issue. Pinmemberrctaubert11-Oct-09 2:37 
QuestionNice job! Is this feature only available in Windows 7? PinmemberHAROLD CHAO22-Sep-09 5:28 
AnswerRe: Nice job! Is this feature only available in Windows 7? Pinmemberrctaubert22-Sep-09 5:35 
GeneralRe: Nice job! Is this feature only available in Windows 7? Pinmemberjaison_jackasljdhfaskldjflkj28-Jun-10 4:26 
GeneralRe: Nice job! Is this feature only available in Windows 7? Pinmemberrctaubert28-Jun-10 4:57 
GeneralRe: Nice job! Is this feature only available in Windows 7? Pinmemberjason728-Jun-10 5:28 
GeneralRe: Nice job! Is this feature only available in Windows 7? Pinmemberrctaubert28-Jun-10 5:48 
GeneralNice discovery! PinmemberJohn Whitmire21-Sep-09 12:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141220.1 | Last Updated 18 Sep 2009
Article Copyright 2009 by rctaubert
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid