0

I am struggling to remove subfolders permissions for a specific group. I've been on internet and of all the solutions I keep getting the error

Object does not belong to a list

Here is my code below:

SPFolder folder = _web.GetFolder(_url + "/" + folderName);
if(folder.Exists)
{                 
    SPPrincipal principal = (SPPrincipal)_group;
    SPRoleAssignment rAssignment = new SPRoleAssignment(_group);                     

    folder.Item.BreakRoleInheritance(true);
    folder.Item.RoleAssignments.Remove(principal);
    folder.Item.Update();
}
4
  • What is the folder you are trying to break permissions on? In a list or library I persume? Commented Dec 11, 2015 at 8:42
  • It's on a List from a subsite Commented Dec 11, 2015 at 9:17
  • so _web is a subweb? Commented Dec 11, 2015 at 9:23
  • Yes it is a sub web. Commented Dec 11, 2015 at 9:37

1 Answer 1

1

You can user below code getting group and then remove it after breaking permission. Hope this helps.

SPFolder folder = _web.GetFolder(_url + "/" + folderName);
if(folder.Exists)
{                                   
    SPPrincipal pri = folder.Item.RoleAssignments.Groups["GroupName"];

    folder.Item.BreakRoleInheritance(true);
    folder.Item.RoleAssignments.Remove(pri);
    folder.Item.Update();
}
6
  • OK I saw the what was the problem when I was requesting the url I didn't include the .url. Now that is correct and I am getting the "value does not fall within the expected range" from the GetFolder Method. Commented Dec 11, 2015 at 9:39
  • What is the url that you are providing ? like Application/sites/subsite/Lists/listname. I guess you are having difficulty in getting folder. Commented Dec 11, 2015 at 9:57
  • Yes and the folderName has a dash like "WHATEVER-THIS" Commented Dec 11, 2015 at 10:14
  • Folder name should not be a problem. as you are giving folder name as string. Are you still getting error ? Can you share your URL which you are giving and foldername I got "WHATEVER-THIS" Commented Dec 11, 2015 at 10:20
  • The foldername should be .......RootFolder=%2fdvdmarketing%2fElementsLibrary%2fSDFDFDFD&Folder Commented Dec 11, 2015 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.