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();
-
- }
- }
Happy SharePointing :-)
Feel Free to Comment for any suggestions or improvements.