共用方式為


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>

備註

使用RoleAssignmentsSPPermissionInfoSecurableObjectListListItemWeb類別屬性,傳回指定物件的角色指派的集合。

若要建立具有沒有角色定義繫結的角色指派,請使用RoleAssignment建構函式。若要新增角色指派繫結的角色定義,使用ImportRoleDefinitionBindings方法。使用**Add(RoleAssignment)**方法RoleAssignmentCollection類別的將角色指派到角色指派的物件的集合。

使用索引子集合傳回單一項目。例如,如果集合被指派到一個名為myRoleAssignments變數, myRoleAssignments[index]中使用 C# 或myRoleAssignments(index)中Visual Basic, 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");
        }
    }
}

執行緒安全

這類型的任何公用 static (共用 於 Visual Basic 中) 成員是安全執行緒。不保證任何執行個體成員都是安全執行緒。

請參閱

參照

RoleAssignmentCollection 成員

Microsoft.SharePoint.Client 命名空間