ItemUpdated event happening twice when you force Check Out option

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





Creative Commons License
Chaks' Corner Blog by Chakkaradeep Chandran is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Based on a work at www.chakkaradeep.com.
Permissions beyond the scope of this license may be available at http://www.chakkaradeep.com.