Let's assume the business scenario here where you need to prevent the Business users from uploading the same document into a SharePoint doucment libary twice.
This can't be achieved through any of the OOTB Features. There is a way to implement this and this is via using SharePoint Event Recevier in Server Side object model.
Here is the Code Snippet presented below to achieve the given scenario.
- public override void ItemAdding(SPItemEventProperties properties)
- {
- base.ItemAdding(properties);
- if (CheckforDuplicates())
- {
- try
- {
- properties.Cancel = true;
- properties.ErrorMessage = "Please choose different document to upload The one you are trying to upload is already there!!.";
- }
- catch (InvalidCreatorIdException ex)
- {
- properties.Cancel = true;
- properties.ErrorMessage = "Duplicate Document Name";
- properties.InvalidateListItem();
- }
- }
Feel Free to Comment for any suggestions or improvements.

Antoine LOIZEAUPosted Feb 23, 2015, 9:31 AM
Hi Lakshmanan Sethu,thanks you for your response but, I think your code is not to "Precent duplicate Document" but just to cancel item event.
Lakshmanan Sethu SankaranarayanPosted Feb 19, 2015, 9:29 AM
Hi Dinesh Kachhaway Antoine LOIZEAU Thank you for valuable time in giving suggestions. I gave the template. we can write our own logic into it. In case if you need any technical assistance, will write another for checking duplicates logic.
Dinesh KachhawayPosted Feb 19, 2015, 5:46 AM
Same question where is that CheckforDuplicates() method?
Antoine LOIZEAUPosted Feb 19, 2015, 5:10 AM
Simply clear code but where is "CheckforDuplicates()" method