ChangedProperties Property - Documentation Error 

We're getting ready to ship the 2.0 version of our "Metadata Extractor" product that extracts metadata out of images and copies it into the list columns. One of the cool new features is that it also extracts the metadata when a new version of a file is uploaded (previously it only did that on the initial upload, which was hard enough, given the problems around the asynchronous ItemAdded eventhandler ...but that's another story ;-).
 
The best way to check what exactly has been changed on an item is to use the ItemUpdating and ItemUpdated events. However when we looked into storing information that was available in the ItemUpdating event that occurs first, so that we could access it in the ItemUpdated afterwards we were a bit confused about the documentation, especially the meaning and usage of the ChangedProperties property. MSDN states that it "gets properties that have changed". Well, not only is that as minimalistic as can be, but also simply wrong:
 
The ChangedProperties property can actually be used to store values from the ItemUpdating event to access them in the following ItemUpdated eventhandler.
 
Example:
If you add the following statement in your ItemUpdating eventhandler:
properties.AfterProperties.ChangedProperties.Add("FILEVERSION", item.File.Versions.Count.ToString());
...then you can access this value in the ItemUpdated eventhandler via:
string previousVersionNumber = properties.AfterProperties["FILEVERSION"].ToString();
Btw, if you step through your code you'll see that the key/value pair is actually being added to the ChangedProperties property. SharePoint then copies it over to the AfterProperties collection before the ItemUpdated eventhandler is invoked.
 
 
Posted on 15-Nov-09 by Jennifer Neumann
0 Comments  |  Trackback Url  |  Link to this post | Bookmark this post with:        
Tags: Sharepoint, Metadata, Digital Asset Management, Code
 

Comments

Name:
URL:
Email:
Comments:

CAPTCHA Image Validation