1

I have already created multiple documents set in a folder, now I want to get those document set I created individually and assign some permission to them,

I just cant seem to be able to retrieve those document set.

1

You can use the GetFolderByServerRelativeUrl method to get the document set.

To break the inheritance, you need to use the BreakRoleInheritance method.

So, try and modify the below sample code:

//assuming that the document set's name is "test"
var docSetFolder = web.GetFolderByServerRelativeUrl("/sites/testsitecollection/Documents/test");
context.Load(docSetFolder, d => d.ListItemAllFields);
context.ExecuteQuery();

var docSetFolderItem = docSetFolder.ListItemAllFields;
docSetFolderItem.BreakRoleInheritance(false, false);
context.ExecuteQuery();

var user = context.Web.EnsureUser("domain\\someuser");
//var approverGroup = context.Web.SiteGroups.GetByName("Approvers");
var roletypes = context.Web.RoleDefinitions.GetByType(RoleType.Reader);

RoleDefinitionBindingCollection collRoleDefinitionBinding = new RoleDefinitionBindingCollection(context);
collRoleDefinitionBinding.Add(roletypes);
docSetFolderItem.RoleAssignments.Add(user, collRoleDefinitionBinding);
//docSetFolderItem.RoleAssignments.Add(approverGroup, collRoleDefinitionBinding);
context.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.