特定组的SharePoint权限 [英] SharePoint permissions for a specific group

查看:151
本文介绍了特定组的SharePoint权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定特定组是否对特定网站集具有读取权限.

I'm trying to establish whether a specific group has Read access to a particular site collection.

我已经尝试了一天半,但感觉好像我发现了三半不同的解决方案!

I have been trying for a day and a half but feel as if I have found three halves of different solutions!

到目前为止,我的代码片段是:

The code fragments I have so far are:

using (SPSite site = new SPSite(this.GenerateAbsoluteUri(moduleCode, academicYear)))
{
    using (SPWeb web = site.OpenWeb())
    {
        for (int i = web.SiteGroups.Count - 1; i >= 0; i--)
        {
            SPGroup group = web.SiteGroups[i];

            if (Regex.IsMatch(group.Name, theGroupImLookingFor))
            {

那又是什么?!

我的大多数Google搜索结果都告诉我有关角色的信息,但我不知道如何将角色与小组联系起来.

Most of my Google results tell me about roles but I don't know how to tie a role to a group.

请帮助!

推荐答案

要将权限分配给用户(帐户)或SharePoint组,需要按特定顺序查看一些对象.我们需要做的第一件事是获取我们想要将角色分配给的安全主体(SPUser或SPGroup).接下来需要做的就是获取我们要分配的实际权限(角色)(例如:读取,完全控制等).然后,我们需要创建一个SPRoleAssignment对象,并在构造函数上将其传递给我们要为其分配权限的SPUser或SPGroup(安全主体).现在,我们需要将角色定义添加到角色分配对象的RoleDefinitionBindings集合中.然后,我们需要将实际角色分配添加到网站(站点)并更新网站.下面是完整的lisitng代码.

To assign permission to a user (account) or a SharePoint group there are some objects that we need to look at in a certain order. The first thing we need to do is get the the security principal that we want to assign the role to (SPUser or SPGroup). The next thing we need to do it get the actual permission (role) that we want to assign (ex: Read, Full Control etc…). Then we need to create a SPRoleAssignment object and on the constructor pass it in the SPUser or SPGroup (security principal) that we want to assign the permissions to. Now we need to add the role definition to the RoleDefinitionBindings collection of the role assignment object. Then we need to add the actual role assignment to the web (site) and update the web. Below is the full code lisitng.

// Create the site that contains our list
using(SPSite oSite = new SPSite("<<my site url>>"))
{
    // Open the web object
  using(SPWeb oWeb = oSite.OpenWeb())
  {

    // Get the group that we want to add the user to
    SPGroup oGroup = oWeb.Groups["<<group name>>"];

    // Get the role definition we want to assign ex: Full Control
    SPRoleDefinition oRole = oWeb.RoleDefinitions["<< role name>>"];

    // Create the role assignment object
    SPRoleAssignment oRoleAssignment = new SPRoleAssignment(oGroup);

    // Add the role definition to the role assignemnt. 
    // This will assign the specific permission to the security principal for this role          assignemnt.
    oRoleAssignment.RoleDefinitionBindings.Add(oRole);

     // Now we need to add the role assignment to the web
     oWeb.RoleAssignments.Add(oRoleAssignment);

    // Now update the web
    oWeb.Update();
   }
}

这篇关于特定组的SharePoint权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆