views:

35

answers:

2

Hi,

Is there a possibility to block chance to add the same data to SPList? I know that two records always are different regarding the ID field. I would like to validate other custom fields added previously by me, and don't allow of adding same field's value. Can anybody tell me how to implement this? I can guess that event receivers could be the answer but I couldn't find how to add a receiver to SPList. Can anybody tel me If I'm right and what is step by step procedure to add such event receiver? I would like to know how to build it and install it using Feature file.

Best Regards

T.S.

+2  A: 

Yes, you can achieve this by writing an event receiver that will handle ItemAdding and ItemUpdating events. You can check if the new value is unique by doing a CAML query on the existing items, and if it isn't, you'll set the event's properties.ErrorMessage and properties.Cancel to true.

You can find enough info about attaching the receiver to lists at http://blogs.msdn.com/brianwilson/archive/2007/03/18/event-handlers-part-3-register-event-handlers-plus-free-site-settings-manage-event-handlers-add-on.aspx

kerray
+1  A: 

Hi,

You are right that's why I'm check your post as answer for my question. But I thing there are better sites for learning event handlers for the beginning users:

1) http://msdn.microsoft.com/en-us/library/ms475328.aspx
2) http://www.c-sharpcorner.com/UploadFile/Chandresh.P/EventHandler04292009070324AM/EventHandler.aspx
3) http://www.wrox.com/WileyCDA/Section/Programming-Event-Handling-in-Windows-SharePoint-Services.id-306329.html

Best Regards T.S.

truthseeker