共用方式為


SecurableObject.BreakRoleInheritance 方法

建立安全物件的唯一角色指派。

命名空間:  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 Overridable Sub BreakRoleInheritance ( _
    copyRoleAssignments As Boolean, _
    clearSubscopes As Boolean _
)
'用途
Dim instance As SecurableObject
Dim copyRoleAssignments As Boolean
Dim clearSubscopes As Boolean

instance.BreakRoleInheritance(copyRoleAssignments, _
    clearSubscopes)
public virtual void BreakRoleInheritance(
    bool copyRoleAssignments,
    bool clearSubscopes
)

參數

  • copyRoleAssignments
    類型:System.Boolean

    指定是否要複製的父安全物件的角色指派。

    如果該值為false的角色指派集合必須包含作業之後包含目前使用者僅 1 的角色指派。

  • clearSubscopes
    類型:System.Boolean

    如果安全的物件是網站,且 clearsubscopes 參數true,必須清除所有的子安全物件在目前的網站和角色指派繼承目前網站的網站中的角色指派,這些安全的物件就會繼承角色指派目前網站在這個呼叫之後。

    如果安全的物件是網站,且 clearsubscopes 參數false,它不會從其上層物件繼承角色指派所有子安全物件的角色指派必須保持不變。

    如果安全物件在網站,而您 clearsubscopes 參數是true必須清除的角色指派所有的子安全的物件,這些安全的物件會在這個呼叫之後從目前的安全物件中繼承角色指派。

    如果安全物件不是一個網站,且 clearsubscopes 參數false,它不會從其上層物件繼承角色指派所有子安全物件的角色指派必須保持不變。

例外狀況

例外狀況 條件
[Microsoft.SharePoint.SPException]

目前的網站是最上層網站。錯誤碼 ︰-2146232832。

[System.InvalidOperationException]

沒有未認可的變更目前的網站。錯誤碼:-1。

[System.UnauthorizedAccessException]

目前的使用者會有足夠的權限。錯誤碼 ︰-2147024891。

備註

如果安全物件已有唯一的角色指派,伺服器必須更改任何角色指派。

範例

此程式碼範例會建立新的權限等級,並會將使用者加入與的權限等級的 [宣告] 清單。

using System;
using Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointFoundation.Samples
{
    class SecurableObject_BreakRoleInheritanceExample
    {
        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");
        }
    }
}

請參閱

參照

SecurableObject 類別

SecurableObject 成員

Microsoft.SharePoint.Client 命名空間