Something that's missing from the default installation of SharePoint is sometimes simple; like picture information. When you place a picture in SharePoint it will not tell you anything about the EXIF information stored in the jpeg file. Using the exifworks class created by Michal A. Valášek to read the information from the picture; we can update the SharePoint listitem. There is a small modification in my exifworks class to get correct readings when converting from rational to int16 or int32 values.

When you install the feature it will register itself for the ItemAdded and ItemUpdating event on lists with ListTemplateId number 109 (the picture library). So when you add a picture to the library our code will be called. The ItemUpdating event is still empty but it should be easy to use when you know how to use the ItemAdded event. When the ItemAdded event is fired a bitmap picture is created by reading the drawing from the file in the listitem that has just been added. This bitmap is passed to our exifworks class to read out the properties. Next we pass the property from the exifworks class to our sub to check if the field exists. If the field does not exist it will create the field on the fly, see code below.

Private Sub GetExifProp(ByVal ListItem As SPListItem, ByVal FieldName As String, ByVal FieldType As String, ByVal prop As Object)

Dim SPFI As SPField

If Not ListItem.Fields.ContainsField(FieldName) Then

SPFI = ListItem.Fields.CreateNewField(FieldType, FieldName)

SPFI.ShowInEditForm = False

ListItem.Fields.Add(SPFI)

End If

ListItem.Item(FieldName) = prop

End Sub

   

Public Overrides Sub ItemAdded(ByVal properties As Microsoft.SharePoint.SPItemEventProperties)

Dim BM As New System.Drawing.Bitmap(properties.ListItem.File.OpenBinaryStream)

Dim EW As New ExifWorks(BM)

Dim LI As SPListItem = properties.ListItem

   

GetExifProp(LI, "ISO", "Text", EW.ISO)

GetExifProp(LI, "EquipmentModel", "Text", EW.EquipmentModel)

GetExifProp(LI, "ShotDate", "DateTime", EW.DateTimeOriginal)

GetExifProp(LI, "FocalLength", "Text", EW.FocalLength)

This will result in any property you wish to be added as metadata to your picture.

To install this feature:

  • Download and unzip this feature somewhere locally
  • Create a directory in your features folder (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES) called myeventhandler. Copy the elements.xml and feature.xml to this directory
  • Register your assembly from the project using: C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\gacutil /i <path to your project>\ bin\Release\myeventhandler.dll
  • Next install the feature: stsadm -o installfeature -filename myeventhandler\feature.xml
  • Now we need to activate the feature on a site you want to use it: stsadm -o activatefeature -filename myeventhandler\feature.xml -url http://www.fabita.nl/test
  • You will now see that the feature is active if you goto the site settings and look under site features.

EventHandler.zip (474,35 kb)