Question

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.

Was it helpful?

Solution

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top