Question

I have follow scenario in my project:

I added a ribbon button to "Edit Item" form - it is available for all types of lists. This button runs .NET code that adds some attachments to the item that is being edited - so it modifies item's attachments collection and calls Update() on this item. Those attachments are being saved properly and user can continue editing item. But when the user clicks "Save" button, an error pops up saying "Save Conflict Your changes conflict with those made concurrently by another user".

Is there any way to make it work properly? I cannot refresh the "Edit item" dialog, because the data that user has already introduced may be lost.

Thanks in advance

Was it helpful?

Solution

For once, I suspect that the error you are receiving is pretty clear on the actual error happening. Just think about it: basically, you are performing a sort of "System update" (I am NOT referring to .SystemUpdate) while the user is performing an "User update".

Your timeline looks like this:

  • user start editing the item
  • Some code that SharePoint knows nothing about edits the currently-edited item
  • the user tries to save: since the original edited item no longer match with the actual one, an error is raised.

Your problem seems to be concurrency of edits.

That said, your best bet is to avoid that concurrency. I see two solutions:

  • move the custom button OUTSIDE the edit form. Make it an operation that is -not- run during an user-initiated edit.

  • if the above is not a solution, you could suffice by further editing the edit form. The idea is to only save the required info for your custom operation when the user clicks the button and perform the actual actions only when he save his change. That way you may be able to perform your update after the user initiated one, thus avoiding the problem.

Notice that the second solution requires delving more in the inner working of the Edit form. If anything else fails, you could use a workaround that requires an event-receiver. Save a flag "user has clicked my custom action" in an hidden field of the list, and use that flag to perform the required actions during the item updated event.

This is only a general idea, hoping it may still be useful.

OTHER TIPS

I think upon clicking the edit button, you should update the UI with a progress bar. When the attachments have been added, redirect the page to the edit form. That'll solve your concurrency problems. You don't have to do the progress bar, but it's nice to have it if your attachment upload takes a noticeable amount of time.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top