ItemUpdated event happening twice when you force Check Out option

by Chakkaradeep 27. April 2009 16:18

Well, today at work, I was really confused why ItemUpdated event in the Document Library was getting called twice. Debugging, it appears that the ItemUpdating event or the ItemUpdated event occurs two times when you enable the Require Check Out option for Document Library! - Thats bad, this was increasing the database requests that we were doing in the ItemUpdated event!

So, Here is THE Solution if you don't want the ItemUpdating and ItemUpdated event get called twice! - http://support.microsoft.com/kb/939307

To work around this behavior, examine the vti_sourcecontrolcheckedoutby property inside an event receiver. If the vti_sourcecontrolcheckedoutby property exits in the BeforeProperties property but not in the AfterProperties property, the event was caused by checking in a document. The following sample code shows you how to do this.

if (properties.AfterProperties["vti_sourcecontrolcheckedoutby"] == null && 
properties.BeforeProperties["vti_sourcecontrolcheckedoutby"] != null)
{
//This is when the update event is triggered by check-in.
}
else
{
//This is triggered by events other than check-in action.
}

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



About the author




NZ SharePoint Conference 2010

 

 

New Zealand SharePoint User Group