02 August 2011

How to Check if a Binary File Has Been Updated in an SPItemEventReceiver

I’ve been dealing with a number of item event receivers in SharePoint and I ran across the need to figure out whether or not the binary file associated with an item in a document library is being updated during the ItemUpdating event.  I knew there were some additional events in the SPItemEventReceiver class, but it turns out that none of them alert you as to when a binary file is actually being updated. 

With the simple option out, I had to turn to a more investigative approach.  So I threw in some code to write out the BeforeProperties and AfterProperties of the properties parameter passed into the ItemUpdating method to see if there was some telltale sign of a binary file update, and there were a few.

So if you want to tell whether or not the binary file has been updated in the ItemUpdating method, you just have to check if vti_docstoreversion has a null value in the AfterProperties collection.  If it has a value, then the binary file has NOT been updated.

There are some additional properties for which this appears to hold true as well:

  • vti_docstoreversion
  • vti_docstoretype
  • vti_metainfoversion
  • vti_contentversionisdirty
  • vti_contenttag
  • vti_modifiedby
  • vti_timelastmodified

I’m not sure if they all always hold true, but they appeared to be consistent in what little testing I did.

Keep up to date with Simple-Talk

For more articles like this delivered fortnightly, sign up to the Simple-Talk newsletter

This post has been viewed 3035 times – thanks for reading.

  • Rate
    [Total: 0    Average: 0/5]
  • Share

Damon Armstrong

Damon Armstrong is a Senior Engineering Team Lead with GimmalSoft in Dallas, Texas, and author of Pro ASP.NET 2.0 Website Programming. He specializes in Microsoft technologies with a focus on SharePoint and ASP.NET. When not staying up all night coding, he can be found playing disc golf, softball, working on something for Carrollton Young Life, or recovering from staying up all night coding.

View all articles by Damon Armstrong