Partager via


SecurableObject Class

An object that can be assigned security permissions.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.Client.ClientObject
    Microsoft.SharePoint.Client.SecurableObject
      Microsoft.SharePoint.Client.List
      Microsoft.SharePoint.Client.ListItem
      Microsoft.SharePoint.Client.Web

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.SecurableObject", ServerTypeId := "{1b1bf348-994e-44fd-823f-0748f5ad94c8}")> _
Public Class SecurableObject _
    Inherits ClientObject
'Usage
Dim instance As SecurableObject
[ScriptTypeAttribute("SP.SecurableObject", ServerTypeId = "{1b1bf348-994e-44fd-823f-0748f5ad94c8}")]
public class SecurableObject : ClientObject

Remarks

The HasUniqueRoleAssignments property is not included in the default scalar property set for this type.

Examples

This code example creates a new permission level and adds a user to the Announcements list with that permission level.

using System;
using Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointFoundation.Samples
{
    class SecurableObjectExample
    {
        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 a securable object to work with (the Announcements list), and use the SecurableObject.BreakPermissions method to break permissions so they can be managed directly.
            SecurableObject listSecurable = site.Lists.GetByTitle("Announcements");
            listSecurable.BreakRoleInheritance(true, false);

            // Use the SecurableObject.roleAssignments property to get the RoleAssignmentCollection for the list.
            RoleAssignmentCollection collRoleAssign = listSecurable.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");
        }
    }
}

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

SecurableObject Members

Microsoft.SharePoint.Client Namespace