1

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

  • As usual, an abstract of your code is very helpful :) – Robert Lindgren Sep 19 '13 at 9:23
  • Does the error still occur after you click your custom ribbon button and close the edit item form, and then opens it again, make some changes and try to save? – user2536 Sep 19 '13 at 10:52
  • @RobertLindgren I'll add it tomorrow as I don't have it now. The button on the ribbon has a javascript that opens a custom aspx page in hidden window and passes ItemId. This aspx page executes .NET code that adds some attachments to this item and calls Update() method. The user continues modifying this item in Edit Form, but he will see an error message on save because this item has already been modified... – movax Sep 19 '13 at 14:49
  • @DanielZiga: No, it happens only if item is modified while the dialog remains open. – movax Sep 19 '13 at 14:50
2

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.

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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