C# Sharepoint - 以编程方式检索用户组和权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/850969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sharepoint - Retrieving user group and permission rights programmatically
提问by
currently I'm trying to retrieve all the groups that is in my sharepoint site. After which, I need to know which users are in the group and the level of site permission for each user. I'm using WSS 3.0 , developing in C# (visual studio 2008). Help really needed as I'm still new in this area. Thanks in advance!
目前我正在尝试检索我的 sharepoint 站点中的所有组。之后,我需要知道组中有哪些用户以及每个用户的站点权限级别。我正在使用 WSS 3.0 ,在 C# (visual studio 2008) 中开发。真的需要帮助,因为我在这方面还是新手。提前致谢!
回答by Daniel Pollard
Groups can be found like:
可以找到以下组:
SPSite siteCollection = new SPSite("site url");
SPWeb site = siteCollection.OpenWeb();
foreach(SPGroup group in site.Groups){
Console.WriteLine(group.Name);
foreach(SPUser u in group.Users){
//will give you users in group, you can then grab the roles of the user
}
}
To find what permissions a role has:
要查找角色具有哪些权限:
SPSite oSiteCollection = SPContext.Current.Site;
using(SPWeb oWebsite = oSiteCollection.AllWebs["Site_Name"])
{
SPMember oMember = oWebsite.Roles["Role_Name"];
oWebsite.Permissions[oMember].PermissionMask =
SPRights.ManageLists | SPRights.ManageListPermissions;
}
The permissions matrix can be found here
权限矩阵可以在这里找到
回答by Shivalik Chakravarty
If you are looking for code to work for using client object model, you may review the following links.
如果您正在寻找用于使用客户端对象模型的代码,您可以查看以下链接。
For getting the groups. http://social.technet.microsoft.com/wiki/contents/articles/24075.how-to-get-sharepoint-user-group-names-in-a-netc-client-application-using-sharepoint-client-object-model.aspx
For getting the permission levels associated with groups. http://social.technet.microsoft.com/wiki/contents/articles/24087.how-to-get-the-permission-levels-associated-with-sharepoint-user-groups-using-client-object-model-in-netc.aspx