C# sharepoint client object model 获取Web和List的权限

Web webSource = contextSource.Web;
contextSource.Load(webSource);
contextSource.ExecuteQuery();

List listSource = ClientOperateInfo.GetListMessage(contextSource, "", ListTitle);
contextSource.Load(listSource);
contextSource.ExecuteQuery();

IEnumerable webroles = contextSource.LoadQuery(webSource.RoleAssignments.Include(roleAsg => roleAsg.Member, roleAsg => roleAsg.RoleDefinitionBindings.Include(roleDef => roleDef.Name, roleDef => roleDef.Hidden)));
contextSource.ExecuteQuery();

IEnumerable listroles = contextSource.LoadQuery(listSource.RoleAssignments.Include(roleAsg => roleAsg.Member, roleAsg => roleAsg.RoleDefinitionBindings.Include(roleDef => roleDef.Name, roleDef => roleDef.Hidden)));
contextSource.ExecuteQuery();

Dictionary<string, string> permisionLists = new Dictionary<string, string>();
foreach (RoleAssignment ra in listroles)
{
RoleDefinitionBindingCollection rdc = ra.RoleDefinitionBindings;
string permission = string.Empty;
foreach (RoleDefinition rdbc in rdc)
{
permission += rdbc.Name.ToString() + ", "; //权限级别
}
permisionLists.Add(ra.Member.Title, permission);
}

//循环输出权限
foreach (var listPermission in permisionLists)
{
Console.WriteLine(listPermission.Key + "..." + listPermission.Value);
}

posted @ 2020-05-29 17:44  SelenaZhou  阅读(184)  评论(0编辑  收藏  举报