0

Preface:

I am trying to develop a wWebPart for displaying items from a document library and let users modify each items metadata. When user updates any documents metadata it will raise an event receiver to do some custom operations and sometimes regenerate the document with updated properties.

Problem:

Whenever user updates metadata from WebPart and submits changes the page reloads showing updated properties for documents. Now the problem is when a document is being regenerated in event receiver user sees old document on WebPart, making them feel like document is not regenerated even if it supposed to be regenerated. Although when user reloads page he will see new document with updated changes as event receiver processing is completed.

Please suggest solution to this incorrect behaviour. I do not want to display old documents on WebPart if it is being submitted for new changes and it is still being processed in event receiver.

Thanks.

1 Answer 1

3

Which event is your Event Receiver trigging on? Because the -ed receivers are asynchronous by default (which could explain the behavior you're seeing).

So, either use ItemUpdating event for your receiver, or explicitly mark your ItemUpdated receiver as synchronous (in the XML or code based on how you are adding the receiver)

For XML: https://blogs.msdn.microsoft.com/unsharepoint/2010/11/09/sharepoint-event-receivers-making-asynchronous-event-synchronous-to-avoid-save-conflict-error/

3
  • I am using ItemUpdated event to handle updates on document library item. Thanks Robert, I think I will look into solution you have provided and let you know if it works. Thanks :) May 16, 2016 at 4:57
  • 1
    It worked. I updated XML in Elements.xml file and added <Synchronization>Synchronous</Synchronization> tag in XML. Thanks again. May 16, 2016 at 5:50
  • Glad I could help May 16, 2016 at 5:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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