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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 04:09:39  来源:igfitidea点击:

Sharepoint - Retrieving user group and permission rights programmatically

c#sharepoint

提问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

权限矩阵可以在这里找到