none
SharePoint中如何停止列表项的权限继承,并删除当前所有访问者,然后授予新的访问者或组予以权限? RRS feed

  • 问题

  • 通过VS,在SharePoint中如何停止列表项的权限继承,并删除当前所有访问者,然后授予新的访问者或组予以权限?谢谢~~~

    Ocode

    2012年7月10日 7:06

答案

  • 这个是我以前写的一个方法,N多个重载就不贴了。 

    /// <summary>
            /// Grant a user or group with a specfic permission level.
            /// </summary>
            /// <param name="securableObject">An SPSecurable Object, can be SPSite, SPWeb, SPList, SPListItem</param>
            /// <param name="principal">SPPrincipal Object, can be a user or group</param>
            /// <param name="roleDefinition">permission level</param>
            /// <param name="clearBeforeAdd">clear all permission levels before added a new one.</param>
            /// <remarks>Lambert@20120411</remarks>
            public void GrantPermission(SPSecurableObject securableObject, SPPrincipal principal, SPRoleDefinition roleDefinition, bool clearBeforeAdd)
            {
                SPRoleAssignment roleAssignment = null;
                try
                {
                    //try to find the role assignment for the user.
                    roleAssignment = securableObject.RoleAssignments.GetAssignmentByPrincipal(principal);
                }
                catch (System.ArgumentException)
                {
                    //The user or group does not exist in the collection at the given scope.
                    roleAssignment = null;
                }
    
                if (roleAssignment == null)
                {
                    roleAssignment = new SPRoleAssignment(principal);
                    roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
                    securableObject.RoleAssignments.Add(roleAssignment);
                }
                else
                {
                    if (clearBeforeAdd) { roleAssignment.RoleDefinitionBindings.RemoveAll(); }
                    if (!roleAssignment.RoleDefinitionBindings.Contains(roleDefinition))
                    {
                        roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
                        roleAssignment.Update();
                    }
                }
            }


    上善若水
    Lambert Qin [秦磊] | 博客(Blog): SharePoint in My Eyes 中文 / LinkedIn
    Posting is provided "AS IS" with no warranties, and confers no rights.


    2012年7月19日 3:25

全部回复

  • 这个是我以前写的一个方法,N多个重载就不贴了。 

    /// <summary>
            /// Grant a user or group with a specfic permission level.
            /// </summary>
            /// <param name="securableObject">An SPSecurable Object, can be SPSite, SPWeb, SPList, SPListItem</param>
            /// <param name="principal">SPPrincipal Object, can be a user or group</param>
            /// <param name="roleDefinition">permission level</param>
            /// <param name="clearBeforeAdd">clear all permission levels before added a new one.</param>
            /// <remarks>Lambert@20120411</remarks>
            public void GrantPermission(SPSecurableObject securableObject, SPPrincipal principal, SPRoleDefinition roleDefinition, bool clearBeforeAdd)
            {
                SPRoleAssignment roleAssignment = null;
                try
                {
                    //try to find the role assignment for the user.
                    roleAssignment = securableObject.RoleAssignments.GetAssignmentByPrincipal(principal);
                }
                catch (System.ArgumentException)
                {
                    //The user or group does not exist in the collection at the given scope.
                    roleAssignment = null;
                }
    
                if (roleAssignment == null)
                {
                    roleAssignment = new SPRoleAssignment(principal);
                    roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
                    securableObject.RoleAssignments.Add(roleAssignment);
                }
                else
                {
                    if (clearBeforeAdd) { roleAssignment.RoleDefinitionBindings.RemoveAll(); }
                    if (!roleAssignment.RoleDefinitionBindings.Contains(roleDefinition))
                    {
                        roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
                        roleAssignment.Update();
                    }
                }
            }


    上善若水
    Lambert Qin [秦磊] | 博客(Blog): SharePoint in My Eyes 中文 / LinkedIn
    Posting is provided "AS IS" with no warranties, and confers no rights.


    2012年7月19日 3:25