Condividi tramite


RoleDefinitionCollection Class

Represents the collection of RoleDefinition objects that define the role definitions that are available for use within the Web site.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.Client.ClientObject
    Microsoft.SharePoint.Client.ClientObjectCollection
      Microsoft.SharePoint.Client.ClientObjectCollection<RoleDefinition>
        Microsoft.SharePoint.Client.RoleDefinitionCollection

Namespace:  Microsoft.SharePoint.Client
Assemblies:   Microsoft.SharePoint.Client.Silverlight (in Microsoft.SharePoint.Client.Silverlight.dll);  Microsoft.SharePoint.Client (in Microsoft.SharePoint.Client.dll)

Syntax

'Declaration
<ScriptTypeAttribute("SP.RoleDefinitionCollection", ServerTypeId := "{964b9ab0-d026-4487-99d1-e06450963cc9}")> _
Public Class RoleDefinitionCollection _
    Inherits ClientObjectCollection(Of RoleDefinition)
'Usage
Dim instance As RoleDefinitionCollection
[ScriptTypeAttribute("SP.RoleDefinitionCollection", ServerTypeId = "{964b9ab0-d026-4487-99d1-e06450963cc9}")]
public class RoleDefinitionCollection : ClientObjectCollection<RoleDefinition>

Examples

This code example defines a new role and adds it to the role definitions collection.

using System;
using Microsoft.SharePoint.Client;

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

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

            // Set up permissions.
            BasePermissions permissions = new BasePermissions();
            permissions.Set(PermissionKind.ManagePermissions);

            // Create a new role definition.
            RoleDefinitionCreationInformation rdcInfo = new RoleDefinitionCreationInformation();
            rdcInfo.Name = "Manage User";
            rdcInfo.Description = "Role for managing user permissions";
            rdcInfo.BasePermissions = permissions;
            rdcInfo.Order = 1;
            RoleDefinition roleDef = site.RoleDefinitions.Add(rdcInfo);

            clientContext.Load(roleDef);
            clientContext.ExecuteQuery();

            Console.WriteLine("Created role: {0}", roleDef.Name);
        }
    }
}

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

RoleDefinitionCollection Members

Microsoft.SharePoint.Client Namespace