Preventing multiple users to edit the same list item in sharepoint 2010

10,480

Solution 1

If I understand your question correctly, you want to prevent further users from editing a list item if someone is already editing it. That can be done using some kind of lock, possibly stored in the list itself, but that strategy suffers from two important flaws:

  • Consider that the first user clicks the link to switch to edit mode, and we lock the list item. If the user just closes his browser without proceeding any further (or his network fails, or his system crashes, or his computer dies), the item will remain locked, and everybody else will be prevented from editing it until we release it somehow (usually after some timeout, or by tinkering with it outside of the web part).

  • Our web part will enforce that lock, but no other code will do so, including SharePoint itself (through another web part or from server-side code) and the whole outside world (through the Client Object Model). So any given list item would still be susceptible to change while the user is editing it, and SPListItem.Update() would still raise an exception if that happens.

A better strategy would be to use SharePoint's own locking mechanism, by checking out the item when the first user switches to edit mode and, of course, enabling the link only if the item is not already checked out.

However, that does not solve the lingering lock problem (when do we check the item back in if the user closes his browser?). Also, CheckOut() is implemented by SPFile, not SPListItem, which means you have to use a document library to benefit from that feature.

All in all, I don't think there's an actually user-friendly solution to your problem: you either let your users edit the same item at the same time and deal with the consequences (only one of them wins), or you don't and you might leave stale locks around (everybody loses).

Solution 2

Use the checkout and checking and then have a workflow which clears locks that are locked for more than a set time period...

Share:
10,480
Janet
Author by

Janet

Updated on June 07, 2022

Comments

  • Janet
    Janet almost 2 years

    We have developed a custom webpart with multiple controls and deployed on sharepoint 2010 site which accepts inputs from the user and once the user clicks on the submit button all the values are stored in the sharepoint list with one of the columns being a hyperlink. When the user clicks on this hyperlink , through the query string he will redirected to the same form again.

    I would like to know if the user has clicked on this hyperlink to make editions to this form, can we avoid another user from making changes to this form?

    Please share your thoughts on this.