This is a new feature in SP 2010. We can’t implement the same thing with the older versions.
We know there are two type of event receivers in sharepoint Synchronous and Asynchronous. Synchronous event will work before the event is completed and Asynchronous event will work after the event is completed.
Let’s see how Changing a Asynchronous Eventhandler to Synchronous Eventhandler can help us while working with event handlers.
Let’s say I am having a document library and I want to update the Title field value with the file name(i.e the Name Field) when a new item is added to the library. For that I have created a ItemAdded eventhandler and attached it to the library.
Now when I upload a single document a edit screen will come after the document is added to the document library but if multiple documents are uploaded we will not get this screen so everything will be fine while uploading multiple documents.
Issue:
When a item is added to the document library ItemAdded will be executed and the Edit Properties screen will be open up. Let’s say the initial Version of the item is 1.0 and as we are updating the Title field of the item within the ItemAdded handler after the updation the version will change Let’s say it’s now 1.1..
Now the version of the item present within the edit page is not the same one we saved in ItemAdded event handler. So when we try to save the new value within the edit page we will get the save conflict error.
So this can be avoid by registering ItemAdded event handler to work as synchronously so that the edit page will be loaded with the updated list item.
How to Achieve this :
//Create an Empty Eventhandler SPEventReceiverDefinitionitemAddedEventRec = lst.EventReceivers.Add(); itemAddedEventRec.Name = "TestItemAdd"; //Set the binding(Bind it as Synchronous) itemAddedEventRec.Synchronization = SPEventReceiverSynchronization.Synchronous; itemAddedEventRec.Type = SPEventReceiverType.ItemAdded; itemAddedEventRec.Assembly = "Assembly Namwe"; itemAddedEventRec.Class = "ClassName"; itemAddedEventRec.Update(); lst.Update();