2

My scenario is i have 2 lists: company and domestic

whenever i create a new company a remote event receiver fires and create a folder in domestic.now when am trying to update an item in company,i added another event receiver to replicate the change to the folder in domestic.

I am having some issues with updating item:

  1. By code am reading the value of the folder name in the edit form page which am using to get the folder object in domestic list. BUT obviosly it tell me the
    folder doesnt exist because the name hasnt been updated yet in domestic list.
  2. IF the above is solved i want to know how to remove all users having permission on that folder

some code snippets:

string folderSetUrl = CompanyType + "/" + CompanyName;



Folder companyfolder = clientContext.Web.GetFolderByServerRelativeUrl(folderSetUrl);
                    companyfolder.ListItemAllFields.ResetRoleInheritance();
                    clientContext.ExecuteQuery();
3

Use this to break role inheritance and remove all permissions.

//method defined by CSOM
public virtual void BreakRoleInheritance(bool copyRoleAssignments, bool clearSubscopes);

//it's use
companyfolder.ListItemAllFields.BreakRoleInheritance(false, false);
companyfolder.Update();
context.ExecuteQuery();

Hope this helps.

  • doesnt work,have a look at my answer – Keshav Taurah Oct 18 '17 at 6:07
3

this worked in my scenario.

List companylibrary = clientContext.Web.Lists.GetByTitle(CompanyType);
                Web site = clientContext.Web;
                companylibrary.BreakRoleInheritance(true, false);
                clientContext.Load(site, s => s.RoleDefinitions);
                clientContext.ExecuteQuery();
                clientContext.Load(companylibrary, l => l.HasUniqueRoleAssignments);
                clientContext.ExecuteQuery();

                if (companylibrary.HasUniqueRoleAssignments)
                {
                    RoleAssignmentCollection oRoleAssignments = companylibrary.RoleAssignments;
                    clientContext.Load(oRoleAssignments);
                    clientContext.ExecuteQuery();

                    foreach (RoleAssignment oRoleAssignment in oRoleAssignments)
                    {
                        clientContext.Load(oRoleAssignment, r => r.Member, r => r.RoleDefinitionBindings);
                        clientContext.ExecuteQuery();
                        Principal oPrincipal = oRoleAssignment.Member;
                        if (oPrincipal.PrincipalType == Microsoft.SharePoint.Client.Utilities.PrincipalType.User)
                        {
                            foreach (RoleDefinition rd in oRoleAssignment.RoleDefinitionBindings)
                            {
                                //if (rd.RoleTypeKind == RoleType.Guest)
                                //{
                                clientContext.Load(rd); oRoleAssignment.RoleDefinitionBindings.Remove(rd);
                                oRoleAssignment.Update();
                                clientContext.Load(oRoleAssignment, r => r.Member, r => r.RoleDefinitionBindings);
                                companylibrary.Update();
                                clientContext.ExecuteQuery();
                                //}
                            }
                        }
                    }
                }

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.