Using CSOM and C#, how can I get the groups that have permissions on a site along with their roles, given that I have the name of the subsite?
Language might be a barrier here, and I tend to explain things more difficult than they really are. So. To get a visual idea of what I'm trying to achieve, please just do the following:
While on a SharePoint site (any site, doesn't matter if it is the top site level or a subsite) on which you have administrator rights, click on the settings icon at the top right and choose "Shared with...". Then click on "Advanced".
You then see a list of groups and their roles (like "Edit", "Read", "Contribute" and so on).
That is what I am trying to retrieve using C#. A list that shows just that.
So far I managed to get a nice list of all groups in a subsite along with their roles, but the list also shows me the groups for each and every page library, document library and list library in the subsite. Basically it shows me all the groups, from all underlaying libraries. And that's not the result I was searching for.
So if there is a way to get the groups for each individual subsite, if possible even for each individual library (because I'll be needing that in the future), then that would be greatly appreciated.
Thanks in advance for your time!
EDIT:
In reply to Brandon C., I adapted your code to this:
if (web.HasUniqueRoleAssignments)
{
RoleAssignmentCollection rCol = web.RoleAssignments;
context.Load(rCol);
context.ExecuteQuery();
foreach (RoleAssignment rAssign in rCol)
{
Console.WriteLine(rAssign.Member + " - " + rAssign.RoleDefinitionBindings);
}
}
However in the console I then get this for each role assignment in the role assignment collection:
Microsoft.SharePoint.Client.Principal - Microsoft.SharePoint.Client.RoleDefinitionBindingCollection