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();
}
  • What is the folder you are trying to break permissions on? In a list or library I persume? – Robert Lindgren Dec 11 '15 at 8:42
  • It's on a List from a subsite – Ed Charles Diesel Dec 11 '15 at 9:17
  • so _web is a subweb? – Robert Lindgren Dec 11 '15 at 9:23
  • Yes it is a sub web. – Ed Charles Diesel Dec 11 '15 at 9:37
0

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();
}
  • 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. – Ed Charles Diesel Dec 11 '15 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. – Bhaskar Dhone Dec 11 '15 at 9:57
  • Yes and the folderName has a dash like "WHATEVER-THIS" – Ed Charles Diesel Dec 11 '15 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" – Bhaskar Dhone Dec 11 '15 at 10:20
  • The foldername should be .......RootFolder=%2fdvdmarketing%2fElementsLibrary%2fSDFDFDFD&Folder – Ed Charles Diesel Dec 11 '15 at 10:31

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.