Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am modifying Word and PDF documents when they are uploaded to a document library with an event receiver.

ItemAdded runs perfect without any errors, I manipulate the documents and save them to library but the users receive an error stating that the document is modified by the SharePoint\System user.

What is the best way to modify the documents as soon as they are uploaded to the library?

Thanks.

share|improve this question
    
what kind of modifications you do in event receiver? –  Amit Kumawat Nov 14 '11 at 10:49
    
Opening the word document with Open XML SDK and putting a dynamically generated string into it's footer and saving the document back. –  Élodie Petit Nov 14 '11 at 10:54
add comment

2 Answers 2

up vote 2 down vote accepted

Maybe you have to register the ItemAdded event as Synchronous event. See this answer how to do it: Race condition in SPListEventReceiver.ListAdded - Save Conflict

share|improve this answer
    
This is more of an unexpected modification imo. The user clicks Add new document button, chooses the file to upload and clicks ok button. In the background, the file is uploaded, my event reciever runs and stamps the document. At the same time, user is shown the second SharePoint upload document dialog in which the user fills the title etc. As soon as the user click ok, she gets an error saying the document is modified by someone else. –  Élodie Petit Nov 14 '11 at 11:21
    
by default, your event receiver works from system account, thus, file is modified and there is change conflict, that's why the error message is shown. –  Yuri Leontyev Nov 14 '11 at 11:55
    
The problem is that your ItemAdded event is Asyonchronous: It modifies the document after/while the user is shown the edit properties dialog of the file. If the ItemAdded event would be Synchronous, then the ItemAdded event modifies the document before the user is shown the edit properties dialog and everything should work fine. –  Matthias Nov 14 '11 at 13:06
add comment

ItemAdded works in asynchronous way after an item is added. If ItemAdded hasn’t finished with its work(or is in queue) and user tries to checkout or edit documents ,they may get this error

Use SPListItem.SystemUpdate(false) instead of SPListItem.Update() in the list Item related to SPFile.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.