Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Sharepoint-以编程方式检索用户组和权限_C#_Sharepoint - Fatal编程技术网

C# Sharepoint-以编程方式检索用户组和权限

C# Sharepoint-以编程方式检索用户组和权限,c#,sharepoint,C#,Sharepoint,目前,我正在尝试检索sharepoint网站中的所有组。之后,我需要知道哪些用户在组中,以及每个用户的站点权限级别。我正在使用WSS3.0,在C#(VisualStudio2008)中开发。 我在这方面还是新手,所以我真的需要帮助。提前谢谢 可以找到如下组: SPSite siteCollection = new SPSite("site url"); SPWeb site = siteCollection.OpenWeb(); foreach(SPGroup group in site.Gr

目前,我正在尝试检索sharepoint网站中的所有组。之后,我需要知道哪些用户在组中,以及每个用户的站点权限级别。我正在使用WSS3.0,在C#(VisualStudio2008)中开发。
我在这方面还是新手,所以我真的需要帮助。提前谢谢

可以找到如下组:

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
   }
}
要查找角色具有的权限,请执行以下操作:

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;
}

权限矩阵可以找到

如果您正在寻找使用客户端对象模型的代码,您可以查看以下链接

  • 为了得到团体。

  • 用于获取与组关联的权限级别。


  • 谢谢你的回复,但是我在listGroup+=(groupCol.Name);”中遇到了错误Microsoft.SharePoint.SPGroupCollection”不包含“名称”的定义,并且找不到接受类型为“Microsoft.SharePoint.SPGroupCollection”的第一个参数的扩展方法“名称”(是否缺少using指令或程序集引用?)foreach(组中的SPUser singleUser.Users)“组”名称在当前上下文中不存在,请给出建议,谢谢!变量groupCol的类型似乎是SPGroupCollection,它没有Name属性(但此集合中的项有)。我提供的代码没有做任何类似的事情。你应该发布你的代码,这样我们就可以看到你做错了什么。你想让我把它粘贴到这里吗?SPGroupCollection groupCol=oWebsite.Groups;foreach(oWebsite.Groups中的SPGroup组){//ListGroup.Text+=(Group.Name)+“
    ”;Label1.Text+=(Group.Name)+“
    ”;}输出是:团队站点成员团队站点所有者团队站点访问者知道为什么吗?ThanksTeam站点成员团队站点所有者团队站点访问者是结果,而不是我的sharepoint站点中的组。知道为什么吗?请导游。感谢此答案在sharepoint(例如WinForms/Console)之外不起作用,因为您无法获取当前网站的上下文。请在您的答案中添加链接的相关部分,以确保即使链接关闭,解决方案也可用。