Tuesday 18 March 2014

Restrict users to overwrite files in document library

The Code should be on 'ItemAdding' event handler. Where you check if the FileName already exist in the List, if yes cancel the adding of document. Since, if you check of 'ItemUpdating' it will stop user from updating the existing document.


 public override void ItemAdding(SPItemEventProperties properties)
{

base.ItemUpdating(properties);
   if (properties.ListItem.File.Exists)
   {
    properties.ErrorMessage = "File Allready exists uploaded by other user.";
    properties.Status = SPEventReceiverStatus.CancelWithError;
    properties.Cancel = true;

   }

}

No comments:

Post a Comment