2

I want to restrict users from editing or deleting others documents, but they can edit/delete there own documents.

In list we get this functionality in advance settings, but in document library it is not available. I tried below two links to get that functionality in document library, but it didn't gave any effect on document library.

http://www.hersheytech.com/blog/changing-the-item-level-permissions-settings-for-a-document-library-requires-powershell

https://stackoverflow.com/questions/735015/edit-only-owned-list-items-in-windows-sharepoint-services-3-0

Some blogs advised to do it using event receiver, but how to check the user who triggered the event is author or not?

If there is another solution for my scenario that will be also welcomed.

  • Have you tried using a list validation where [Created By]=[Modified By]? – user43828 Jul 1 '15 at 17:17
  • Hi Solomon, my issue got resolved by below answer. But still i will be interested in what you suggested. Do you have any examples on how to do this. I checked validation setting of document library, but created by and modified by column were not there to add in formula. – P S Jul 2 '15 at 6:59
3

my issue got resolved with help of below link https://dotnetadil.wordpress.com/2012/04/11/sharepoint-item-deleting-event-receiver-deny-delete/

I used below code

    public override void ItemDeleting(SPItemEventProperties properties)
            {
                base.ItemDeleting(properties);

                using (SPWeb web = properties.OpenWeb())
                {                
                    SPUser creator = new SPFieldUserValue(web, properties.ListItem["Author"].ToString()).User;
                    SPUser currentuser = web.SiteUsers.GetByID(properties.CurrentUserId);

                    bool isCurrentUserCreator = creator.ID.Equals(currentuser.ID);

                    if (!isCurrentUserCreator)
                    {
                        string errormsg = "You can delete own documents only";

                        properties.ErrorMessage = errormsg;
                        properties.Status = SPEventReceiverStatus.CancelWithError;   
                    }
                }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.