SPWeb sp Web = Get SPWeb Instance(); // assuming that you have a document library by name of "My List" SPList shared Documents = web. SPEvent Receiver Definition sp Event Receiver Def = shared Documents. This is the reason why Item Updating and Item Updated are called twice (once for each step of check-in process). And Item Updated gets called after the item is updated.
This could have been implemented using Session State, but this is not available in events ending with "ed" in Event Receivers and probably not the best option anyway for several reasons.
It is not enough to call the remove method like so: This call will not necessarily remove the item from the bag--in my case it did not, however setting it to null will.
For documents, Before and After properties are guaranteed for post events, such as Item Updating and Item Updated, but Before properties are not available for post events on list items.
So, if we go back to our original problem listed above.
And if you have Update() or System Update() call on the document / item, this leads to getting an exception message on screen about “XYZ has already been modified”. When force checkout is enabled on document library, this is how the document editing works : When you checkout a document for editing, a local copy of the document is created that saves all the changes made by the user.
This happens due to race condition between the two threads when updating the document / item. At the time of checking-in the document, this local copy updates the original copy (even if there are no changes), then there is another request that does check-in on the document.
Regardless of what I tried, I really couldn't track down exactly why it was getting fired twice.
To work around this issue, I implemented the following code: The code looks for the key (the Doc ID) in the property bag and if it is present, skip the creation of the task and remove the property from the bag.
Sequence = 5000; // put any number here sp Event Receiver Def. Item Updating gets called synchronously just before an item is updated.