0

I have a document library where many users can upload a document and start workflows on that individual document.

There is option to restrict edit/delete of lists items based on the current user credentials but isn't there any way to do the same for the Document Library documents?

I want to be able to restrict EDIT/DELETE of a document based on my custom logic. The logic is somewhat like this: Document can only be edited by the user who uploaded the document only when the 'status' column of the library is set to "allowed for Editing"

So where do I implement this kind of logic?

5
  • From where status column set to "allowed for Editing"? Commented Mar 3, 2017 at 4:59
  • I am setting it up using an "impersonation Step" when someone starts a workflow of that document library. @Sam
    – Raxak
    Commented Mar 3, 2017 at 5:04
  • Okie...Then you can put event receiver on item updated and then break permission base on your requirement and give edit permission to that user when column value set to "allowed for Editing". Commented Mar 3, 2017 at 5:07
  • Is it a good idea to break permissions everytime? I am in a sharepoint Server that has 1000+ users and 500+ people are going to be using this workflow. Isn't breaking permission going to cause the system performance to be slow? Is there any other alternative that you know of?
    – Raxak
    Commented Mar 3, 2017 at 5:17
  • I think it is best option for your requirement and at a time i think 500-100 items permission not break so i think it's not cause to much performance issue. Commented Mar 3, 2017 at 5:59

1 Answer 1

2

One option to avoid delete will be on Itemdeleting event you can check whether user is Author of the document and then cancel/execute event depending on condition.

    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;   
                    }
                }
}

I had similar question sometime back and I used above code to restrict user from deleting documents of other user.

How to restrict user from deleting\editing documents if user is not author of that document

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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