0
    public bool BreakListItemRoleInheritance(string siteUrl, Guid listId, int itemId, bool copyRoleAssignments)
    {

        try
        {
            var clientContext = Admin.GetAuthenticatedClientContext(siteUrl);
            var spWeb = clientContext.Web;

            var spList = spWeb.Lists.GetById(listId);
            var spItem = spList.GetItemById(itemId);

            clientContext.Load(spItem, item => item.HasUniqueRoleAssignments, item => item.DisplayName);
            clientContext.ExecuteQuery();

            if (spItem == null)
                throw new NullReferenceException(string.Format("Item '{0}' in List '{1}' in Web '{2}'", itemId, listId, siteUrl));

            if (!spItem.HasUniqueRoleAssignments)
            {
                spItem.BreakRoleInheritance(copyRoleAssignments, false);
                clientContext.ExecuteQuery();
            }
            else
                LogWriteLine("Not breaking inheritance for item {0}. Already broken.", spItem.DisplayName);

            return true;
        }
        catch (Exception ex)
        {
            LogWriteLine("Failed to break Role Inheritance for Item '{0}' in List '{1}' in Site '{2}'", itemId, listId, siteUrl, ex);
            throw ex;
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.