0

I want to copy role assignments from one folder and set it to other folder

I am basically creating a subfolder and I want that folder to have same permission as its sibling

I tried

Folder sourceFolder = oWeb.GetFolderByServerRelativeUrl("Affaires/Test Affaire/Mails");
ctx.Load(sourceFolder);
ctx.ExecuteQuery();
Folder destinationFolder = folder.Folders.Add("Demo");  
destinationFolder.ListItemAllFields.BreakRoleInheritance(false, false);
RoleAssignmentCollection roleAssignments = sourceFolder.ListItemAllFields.RoleAssignments;
ctx.Load(roleAssignments);
ctx.ExecuteQuery();
foreach (RoleAssignment item in roleAssignments)
        {
        //not sure what to do here!
         destinationFolder.ListItemAllFields.RoleAssignments.Add(item.PrincipalId, item.RoleDefinitionBindings);
         }
2

I figured it out

The below code worked for me

Folder sourceFolder = oWeb.GetFolderByServerRelativeUrl("Affaires/Test Affaire/Mails");
ctx.Load(sourceFolder);
ctx.ExecuteQuery();
Folder destinationFolder = folder.Folders.Add("Demo");
destinationFolder.ListItemAllFields.BreakRoleInheritance(false, false);
RoleAssignmentCollection roleAssignments = sourceFolder.ListItemAllFields.RoleAssignments;
ctx.Load(roleAssignments);
ctx.ExecuteQuery();
foreach (RoleAssignment item in roleAssignments)
{
  ctx.Load(item);
  ctx.ExecuteQuery();
  destinationFolder.ListItemAllFields.RoleAssignments.Add(item.Member,item.RoleDefinitionBindings);
}
ctx.Load(destinationFolder);
ctx.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.