SharePoint 2010 Document Lifecycle from an Event Receiver Point of View


On a recent project I needed to write an Event Receiver for a document library which set item level security on the document library items. Given the nature of document content management and the various ways in which a document library can be configured (content types, approval, check-in/out, versioning etc) I needed to understand the lifecycle sequence and events a document may pass through.

In researching this I rediscovered a great post from Synergy which describes the semantics of BeforeProperties and AfterProperties. I also wrote a test EventReceiver which recorded events and item properties which together I used to build up a picture of a documents lifecycle from an EventReceivers point of view, based on various document library configurations.

The data I gathered and presented below is part of the story, but of course, not the whole story, but was sufficient for me to understand which item event receiver methods to implement and under what conditions I would change an items security permissions.

Note the difference when adding new documents to a document library using the “Upload” method, and the document library is managing content types – after the document is added to the document library, its metadata is updated after the user has selected the content type and filled out the properties in the UI, which causes the additional calls to ItemUpdating & ItemUpdated.

Document Library that is not Managing Content Types

No Versioning or Major Versioning
No Approval
New Document ItemAdded Item.File.Level = Published
Item _ModerationStatus = 0
Upload Document ItemAdded Item.File.Level = Published
Item _ModerationStatus = 0
Major/Minor Versioning
No Approval
New Document ItemAdded Item.File.Level = Draft
Item _ModerationStatus = 3
> Publish Major Version ItemUpdating Item.File.Level = Draft
Item _ModerationStatus = 3
ItemUpdated Item.File.Level = Published
Item _ModerationStatus = 0
Upload Document ItemAdded Item.File.Level = Draft
Item _ModerationStatus = 3
> Publish Major Version ItemUpdating Item.File.Level = Draft
Item _ModerationStatus = 3
ItemUpdated Item.File.Level = Published
Item _ModerationStatus = 0
Major/Minor Versioning
Approval
New Document ItemAdded Item.File.Level = Draft
Item _ModerationStatus = 3
Item.ModerationInformation.Status = Draft
> Publish Major Version ItemUpdating Item.File.Level = Draft
Item _ModerationStatus = 3
Item.ModerationInformation.Status = Draft
ItemUpdated Item.File.Level = Draft
Item _ModerationStatus = 2
Item.ModerationInformation.Status = Pending
> Approve ItemUpdating Item.File.Level = Draft
Item _ModerationStatus = 2
Item.ModerationInformation.Status = Pending
ItemUpdated Item.File.Level = Published
Item _ModerationStatus = 0
Item.ModerationInformation.Status = Approved
Upload Document ItemAdded Item.File.Level = Draft
Item _ModerationStatus = 3
Item.ModerationInformation.Status = Draft
> Publish Major Version ItemUpdating Item.File.Level = Draft
Item _ModerationStatus = 3
Item.ModerationInformation.Status = Draft
ItemUpdated Item.File.Level = Draft
Item _ModerationStatus = 2
Item.ModerationInformation.Status = Pending
> Approve ItemUpdating Item.File.Level = Draft
Item _ModerationStatus = 2
Item.ModerationInformation.Status = Pending
ItemUpdated Item.File.Level = Published
Item _ModerationStatus = 0
Item.ModerationInformation.Status = Approved

Document Library that is Managing Content Types

No Versioning or Major Versioning
No Approval
New Document ItemAdded Item.File.Level = Published
Item _ModerationStatus = 0
Upload Document ItemAdded Item.File.Level = Published
Item _ModerationStatus = 0
ItemUpdating Item.File.Level = Published
Item _ModerationStatus = 0
ItemUpdated Item.File.Level = Published
Item _ModerationStatus = 0
Major/Minor Versioning
No Approval
New Document ItemAdded Item.File.Level = Draft
Item _ModerationStatus = 3
> Publish Major Version ItemUpdating Item.File.Level = Draft
Item _ModerationStatus = 3
ItemUpdated Item.File.Level = Published
Item _ModerationStatus = 0
Upload Document ItemAdded Item.File.Level = Draft
Item _ModerationStatus = 3
ItemUpdating Item.File.Level = Draft
Item _ModerationStatus = 3
ItemUpdated Item.File.Level = Draft
Item _ModerationStatus = 3
> Publish Major Version ItemUpdating Item.File.Level = Draft
Item _ModerationStatus = 3
ItemUpdated Item.File.Level = Published
Item _ModerationStatus = 0
Major/Minor Versioning
Approval
New Document ItemAdded Item.File.Level = Draft
Item _ModerationStatus = 3
Item.ModerationInformation.Status = Draft
> Publish Major Version ItemUpdating Item.File.Level = Draft
Item _ModerationStatus = 3
Item.ModerationInformation.Status = Draft
ItemUpdated Item.File.Level = Draft
Item _ModerationStatus = 2
Item.ModerationInformation.Status = Pending
> Approve ItemUpdating Item.File.Level = Draft
Item _ModerationStatus = 2
Item.ModerationInformation.Status = Pending
ItemUpdated Item.File.Level = Published
Item _ModerationStatus = 0
Item.ModerationInformation.Status = Approved
Upload Document ItemAdded Item.File.Level = Draft
Item _ModerationStatus = 3
Item.ModerationInformation.Status = Draft
ItemUpdating Item.File.Level = Draft
Item _ModerationStatus = 3
Item.ModerationInformation.Status = Draft
ItemUpdated Item.File.Level = Draft
Item _ModerationStatus = 3
Item.ModerationInformation.Status = Draft
> Publish Major Version ItemUpdating Item.File.Level = Draft
Item _ModerationStatus = 3
Item.ModerationInformation.Status = Draft
ItemUpdated Item.File.Level = Draft
Item _ModerationStatus = 2
Item.ModerationInformation.Status = Pending
> Approve ItemUpdating Item.File.Level = Draft
Item _ModerationStatus = 2
Item.ModerationInformation.Status = Pending
ItemUpdated Item.File.Level = Published
Item _ModerationStatus = 0
Item.ModerationInformation.Status = Approved

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

One thought on “SharePoint 2010 Document Lifecycle from an Event Receiver Point of View

  1. hi phil,
    thx for that helpful information!
    I am currently developing an event receiver for a document library as well. i added a synchronous itemupdated event receiver that sets permissions with elevated privileges. i now experience a problem that after my successful changes, an error is thrown in the SharePoint code (System.ArgumentOutOfRangeException). In the SharePoint code a query for the element is done which seems to cannot find the item I just added to the library. This does not happen if I’m logged in with a site collection admin. Did you come across that problem as well? (I tried to change to async processing, but then I get errors in other places of my code).
    I’d really appreciate your help!
    thx, mel

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s