1
votes

I Want to have only unique values in a SharePoin List. To achieve this I can use 'ItemAdding' event handler as mentioned in the below link.

http://weblogs.asp.net/vikram/archive/2008/12/24/sharepoint-using-event-handler-to-make-a-column-unique.aspx

Now I have a Doubt: Suppose that two user tries to add list Item in the list with the same column value(which requires unique value) at the same Time. will ItemAdding event would be fired at the same time for both call? If so then there is a possibility that two items having same value in the column. Please confirm.

2
Ok in my application I am programatically adding list item on button click action in custom page. So one possibility is to use lock or mutex so that at a time only one thread can create list item and before creating the item I can check for duplicate. Here again I have a doubt: What will happen in load balanced multiserver scenario? I mean if two request goes on two different server so again they can execute parallely. Is there any mechnism using which I can achieve syncronisation across machine?Anoop

2 Answers

1
votes

I think, this method allows you only to have semi-unique values in the column. That is, if everything is normal, it will be unique. However, you cannot compare the properties of two items being added simultaneously (and yes, it may happen, since IIS web server is multi-threaded). Hence you might have duplicate values as a result.

A workaround - implement a "ItemAdded" event handler, too and delete a newly added item, if it has that property the same as some other existing item. This will, of course, happen very rarely.

0
votes

If you have enough concurrent users that this is likely to be a problem, SharePoint probably isn't the right tool for the job. If the value is created by the user, it is extremely unlikely that two users will be adding the same value at the same time. If it is automatically generated, you probably should be using something based on ID, which is known to be unique.

If you are worried about the possibility of duplicates anyway, just make sure that the field can be edited if you do end up with duplicates causing problems.