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.


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

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

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

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.