How custom event receivers affect OnePlaceMail upload process
Article describes inconsistent upload issues and ways of fixing them.
Library event receivers may affect the OnePlaceMail uploading process resulting in inconsistent errors.
File has been modified error. There could be several problematic emails in the upload results window, but some of them are uploaded succesfully:
Metadata was not populated. Some of the email messages left without email properties updated after uploading several emails:
OnePlaceMail uploads an email message in several steps and some of them include the following events:
- ItemAdding - when msg or other file type is uploaded into library this event is triggered - occurs before added
- ItemAdded - when msg or other file type is uploaded into library this event is triggered - occurs after added
- ItemUpdating - we get the item again in library and apply the metadata to item so this event is triggered - occurs before metadata applied
- ItemUpdated - we get the item again in library and apply the metadata to item so this event is triggered - occurs after metadata applied
Any custom code written in these event handlers could cause an issue.
Library event receivers have one of the two synchronization types either Asynchronous or Synchronous.
Asynchronous event receivers are executed after committing the file to the database, thus it could happen before 3rd step of OnePlaceMail process (which leads to the error “The file has been modified” or doesn't allow OnePlaceMail to successfully update library columns).
It is highly dependent on the network and server speed; that is why this issue is not 100% reproducible.
For more information about event receivers synchronization type please refer to the following Microsoft KB article: SPItemEventReceiver methods
It's possible to use one of the email properties as a flag of OnePlaceMail has finished its job. E.g. custom event handlers should fire only after EmDateSent has been updated in the library.
Another option is to change synchronization method of the event receiver:
SharePoint 2007 and older versions
According to the SPEventReceiverDefinition Properties for WSS3 there is no property which allows to change synchronization method of the event receiver. To change the event receiver behaviour you could change it's type to make it synchronous (e.g. change type from ItemAdded to ItemAdding).
SharePoint 2010 and newer versions
If synchronization method of the event receiver is changed to “Synchronous” then the event will fire before committing the file to the database thus not conflicting with OnePlaceMail process.