RoleAssignmentCollection 类

表示定义为每个安全对象的所有角色分配RoleAssignment对象的集合。

继承层次结构

System.Object
  Microsoft.SharePoint.Client.ClientObject
    Microsoft.SharePoint.Client.ClientObjectCollection
      Microsoft.SharePoint.Client.ClientObjectCollection<RoleAssignment>
        Microsoft.SharePoint.Client.RoleAssignmentCollection

命名空间:  Microsoft.SharePoint.Client
程序集:   Microsoft.SharePoint.Client.Silverlight(位于 Microsoft.SharePoint.Client.Silverlight.dll 中);  Microsoft.SharePoint.Client.Phone(位于 Microsoft.SharePoint.Client.Phone.dll 中)  Microsoft.SharePoint.Client(位于 Microsoft.SharePoint.Client.dll 中)

语法

声明
Public NotInheritable Class RoleAssignmentCollection _
    Inherits ClientObjectCollection(Of RoleAssignment)
用法
Dim instance As RoleAssignmentCollection
public sealed class RoleAssignmentCollection : ClientObjectCollection<RoleAssignment>

备注

RoleAssignments属性的SPPermissionInfoSecurableObjectListListItemWeb课程,用于返回给定对象的角色分配的集合。

若要创建具有无角色定义绑定的角色分配,请使用RoleAssignment构造函数。若要添加绑定的角色定义角色分配,请使用ImportRoleDefinitionBindings方法。使用RoleAssignmentCollection类Add(RoleAssignment) 方法添加角色分配到的对象的角色分配的集合。

使用索引从集合中返回单个项目。例如,如果集合分配给一个名为myRoleAssignments变量,使用myRoleAssignments[index]中 C# 或myRoleAssignments(中Visual Basic,index)index所在的索引集合中的项目或包含角色定义的名称的字符串。

示例

此代码示例创建新的权限级别,并将用户添加到通知列表中具有该权限级别。

using System;
using Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointFoundation.Samples
{
    class RoleAssignmentCollectionExample
    {
        static void Main()
        {
            string siteUrl = "http://MyServer/sites/MySiteCollection";

            ClientContext clientContext = new ClientContext(siteUrl);
            Site collSite = clientContext.Site;
            Web site = clientContext.Web;

            // Set up permissions.
            BasePermissions permissions = new BasePermissions();
            permissions.Set(PermissionKind.ViewListItems);
            permissions.Set(PermissionKind.AddListItems);
            permissions.Set(PermissionKind.EditListItems);
            permissions.Set(PermissionKind.DeleteListItems);

            // Create a new role definition.
            RoleDefinitionCreationInformation rdcInfo = new RoleDefinitionCreationInformation();
            rdcInfo.Name = "Manage List Items";
            rdcInfo.Description = "Allows a user to manage list items";
            rdcInfo.BasePermissions = permissions;
            RoleDefinition roleDef = collSite.RootWeb.RoleDefinitions.Add(rdcInfo);

            // Create a new RoleDefinitionBindingCollection object.
            RoleDefinitionBindingCollection collRDB = new RoleDefinitionBindingCollection(clientContext);
            // Add the role to the collection.
            collRDB.Add(roleDef);

            // Get the list to work with and break permissions so its permissions can be managed directly.
            List targetList = site.Lists.GetByTitle("Announcements");
            targetList.BreakRoleInheritance(true, false);

            // Get the RoleAssignmentCollection for the target list.
            RoleAssignmentCollection collRoleAssign = targetList.RoleAssignments;
            // Add the user to the target list and assign the user to the new RoleDefinitionBindingCollection.
            RoleAssignment rollAssign = collRoleAssign.Add(site.CurrentUser, collRDB);

            clientContext.ExecuteQuery();

            Console.WriteLine("Security modified");
        }
    }
}

线程安全性

该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。

另请参阅

引用

RoleAssignmentCollection 成员

Microsoft.SharePoint.Client 命名空间