Search Results for

    Show / Hide Table of Contents

    Class SecurityExtensions

    This manager class holds security related methods

    Inheritance
    System.Object
    SecurityExtensions
    Namespace: Microsoft.SharePoint.Client
    Assembly: PnP.Framework.dll
    Syntax
    public static class SecurityExtensions : object

    Methods

    AddAdministrators(Web, List<UserEntity>, Boolean)

    Add a site collection administrator to a site collection

    Declaration
    public static void AddAdministrators(this Web web, List<UserEntity> adminLogins, bool addToOwnersGroup = false)
    Parameters
    Web web

    Site to operate on

    List<UserEntity> adminLogins

    Array of admins loginnames to add

    System.Boolean addToOwnersGroup

    Optionally the added admins can also be added to the Site owners group

    AddGroup(Web, String, String, Boolean, Boolean, Boolean)

    Adds a group

    Declaration
    public static Group AddGroup(this Web web, string groupName, string groupDescription, bool groupIsOwner, bool updateAndExecuteQuery = true, bool onlyAllowMembersViewMembership = false)
    Parameters
    Web web

    Site to add the group to

    System.String groupName

    Name of the group

    System.String groupDescription

    Description of the group

    System.Boolean groupIsOwner

    Sets the created group as group owner if true

    System.Boolean updateAndExecuteQuery

    Set to false to postpone the executequery call

    System.Boolean onlyAllowMembersViewMembership

    Set whether members are allowed to see group membership, defaults to false

    Returns
    Group

    The created group

    AddPermissionLevelToGroup(SecurableObject, String, RoleType, Boolean)

    Add a permission level (e.g.Contribute, Reader,...) to a group

    Declaration
    public static void AddPermissionLevelToGroup(this SecurableObject securableObject, string groupName, RoleType permissionLevel, bool removeExistingPermissionLevels = false)
    Parameters
    SecurableObject securableObject

    Web/List/Item to operate against

    System.String groupName

    Name of the group

    RoleType permissionLevel

    Permission level to add

    System.Boolean removeExistingPermissionLevels

    Set to true to remove all other permission levels for that group

    AddPermissionLevelToGroup(SecurableObject, String, String, Boolean)

    Add a role definition (e.g.Contribute, Read, Approve) to a group

    Declaration
    public static void AddPermissionLevelToGroup(this SecurableObject securableObject, string groupName, string roleDefinitionName, bool removeExistingPermissionLevels = false)
    Parameters
    SecurableObject securableObject

    Web/List/Item to operate against

    System.String groupName

    Name of the group

    System.String roleDefinitionName

    Name of the role definition to add, Full Control|Design|Contribute|Read|Approve|Manage Hierarchy|Restricted Read. Use the correct name of the language of the root site you are using

    System.Boolean removeExistingPermissionLevels

    Set to true to remove all other permission levels for that group

    AddPermissionLevelToPrincipal(SecurableObject, Principal, RoleType, Boolean)

    Add a permission level (e.g.Contribute, Reader,...) to a group

    Declaration
    public static void AddPermissionLevelToPrincipal(this SecurableObject securableObject, Principal principal, RoleType permissionLevel, bool removeExistingPermissionLevels = false)
    Parameters
    SecurableObject securableObject

    Web/List/Item to operate against

    Principal principal

    Principal to add permission to

    RoleType permissionLevel

    Permission level to add

    System.Boolean removeExistingPermissionLevels

    Set to true to remove all other permission levels for that group

    AddPermissionLevelToPrincipal(SecurableObject, Principal, String, Boolean)

    Add a role definition (e.g.Contribute, Read, Approve) to a group

    Declaration
    public static void AddPermissionLevelToPrincipal(this SecurableObject securableObject, Principal principal, string roleDefinitionName, bool removeExistingPermissionLevels = false)
    Parameters
    SecurableObject securableObject

    Web/List/Item to operate against

    Principal principal

    Principal to add permission to

    System.String roleDefinitionName

    Name of the role definition to add, Full Control|Design|Contribute|Read|Approve|Manage Hierarchy|Restricted Read. Use the correct name of the language of the root site you are using

    System.Boolean removeExistingPermissionLevels

    Set to true to remove all other permission levels for that group

    AddPermissionLevelToUser(SecurableObject, String, RoleType, Boolean)

    Add a permission level (e.g.Contribute, Reader,...) to a user

    Declaration
    public static void AddPermissionLevelToUser(this SecurableObject securableObject, string userLoginName, RoleType permissionLevel, bool removeExistingPermissionLevels = false)
    Parameters
    SecurableObject securableObject

    Web/List/Item to operate against

    System.String userLoginName

    Loginname of the user

    RoleType permissionLevel

    Permission level to add

    System.Boolean removeExistingPermissionLevels

    Set to true to remove all other permission levels for that user

    AddPermissionLevelToUser(SecurableObject, String, String, Boolean)

    Add a role definition (e.g.Contribute, Read, Approve) to a user

    Declaration
    public static void AddPermissionLevelToUser(this SecurableObject securableObject, string userLoginName, string roleDefinitionName, bool removeExistingPermissionLevels = false)
    Parameters
    SecurableObject securableObject

    Web/List/Item to operate against

    System.String userLoginName

    Loginname of the user

    System.String roleDefinitionName

    Name of the role definition to add, Full Control|Design|Contribute|Read|Approve|Manage Hierarchy|Restricted Read. Use the correct name of the language of the root site you are using

    System.Boolean removeExistingPermissionLevels

    Set to true to remove all other permission levels for that user

    AddReaderAccess(Web)

    Add read access to the group "Everyone except external users".

    Declaration
    public static User AddReaderAccess(this Web web)
    Parameters
    Web web

    Site to be processed - can be root web or sub site

    Returns
    User

    AddReaderAccess(Web, BuiltInIdentity)

    Add read access to the group "Everyone except external users".

    Declaration
    public static User AddReaderAccess(this Web web, BuiltInIdentity user)
    Parameters
    Web web

    Site to be processed - can be root web or sub site

    BuiltInIdentity user

    Built in user to add to the visitors group

    Returns
    User

    AddUserToGroup(Web, Group, String)

    Adds a user to a group

    Declaration
    public static void AddUserToGroup(this Web web, Group group, string userLoginName)
    Parameters
    Web web

    Web to operate against

    Group group

    Group object representing the group

    System.String userLoginName

    Login name of the user

    AddUserToGroup(Web, Group, User)

    Adds a user to a group

    Declaration
    public static void AddUserToGroup(this Web web, Group group, User user)
    Parameters
    Web web

    Web to operate against

    Group group

    Group object representing the group

    User user

    User object representing the user

    AddUserToGroup(Web, Int32, String)

    Adds a user to a group

    Declaration
    public static void AddUserToGroup(this Web web, int groupId, string userLoginName)
    Parameters
    Web web

    web to operate against

    System.Int32 groupId

    Id of the group

    System.String userLoginName

    Login name of the user

    AddUserToGroup(Web, String, String)

    Adds a user to a group

    Declaration
    public static void AddUserToGroup(this Web web, string groupName, string userLoginName)
    Parameters
    Web web

    web to operate against

    System.String groupName

    Name of the group

    System.String userLoginName

    Loginname of the user

    AssociateDefaultGroups(Web, Group, Group, Group)

    Associate the provided groups as default owners, members or visitors groups. If a group is null then the association is not done

    Declaration
    public static void AssociateDefaultGroups(this Web web, Group owners, Group members, Group visitors)
    Parameters
    Web web

    Site to operate on

    Group owners

    Owners group

    Group members

    Members group

    Group visitors

    Visitors group

    GetAdministrators(Web)

    Get a list of site collection administrators

    Declaration
    public static List<UserEntity> GetAdministrators(this Web web)
    Parameters
    Web web

    Site to operate on

    Returns
    List<UserEntity>

    List of UserEntity objects

    GetAllUniqueRoleAssignments(Web, Int32)

    Get all unique role assignments for a web object and all its descendents down to document or list item level.

    Declaration
    public static IEnumerable<RoleAssignmentEntity> GetAllUniqueRoleAssignments(this Web web, int leafBreadthLimit = null)
    Parameters
    Web web

    The current web object to be processed.

    System.Int32 leafBreadthLimit

    Skip further visiting on this branch if the number of child items or documents with unique role assignments exceeded leafBreadthLimit. When setting to 0, the process will stop at list / document library level.

    Returns
    IEnumerable<RoleAssignmentEntity>

    Returns all role assignments

    GetAuthenticationRealm(Web)

    Returns the authentication realm for the current web

    Declaration
    public static Guid GetAuthenticationRealm(this Web web)
    Parameters
    Web web

    The Current site

    Returns
    Guid

    Returns Realm in Guid

    GetEveryoneExceptExternalUsersClaimName(Web)

    Returns the correct value of the "Everyone except external users" string value

    Declaration
    public static string GetEveryoneExceptExternalUsersClaimName(this Web web)
    Parameters
    Web web

    Web to get the language from

    Returns
    System.String

    String in correct translation

    GetExternalUsersForSiteTenant(Web, Uri)

    Returns a list all external users for a given site that have at least the viewpages permission

    Declaration
    public static List<ExternalUserEntity> GetExternalUsersForSiteTenant(this Web web, Uri siteUrl)
    Parameters
    Web web

    Tenant administration web

    Uri siteUrl

    Url of the site fetch the external users for

    Returns
    List<ExternalUserEntity>

    A list of ExternalUserEntity objects

    GetExternalUsersTenant(Web)

    Returns a list all external users in your tenant

    Declaration
    public static List<ExternalUserEntity> GetExternalUsersTenant(this Web web)
    Parameters
    Web web

    Tenant administration web

    Returns
    List<ExternalUserEntity>

    A list of ExternalUserEntity objects

    GetGroupID(Web, String)

    Returns the integer ID for a given group name

    Declaration
    public static int GetGroupID(this Web web, string groupName)
    Parameters
    Web web

    Site to be processed - can be root web or sub site

    System.String groupName

    SharePoint group name

    Returns
    System.Int32

    Integer group ID

    GetPrincipalUniqueRoleAssignments(Web, Principal, Int32)

    Get all unique role assignments for a user or a group in a web object and all its descendents down to document or list item level.

    Declaration
    public static IEnumerable<RoleAssignmentEntity> GetPrincipalUniqueRoleAssignments(this Web web, Principal principal, int leafBreadthLimit = null)
    Parameters
    Web web

    The current web object to be processed.

    Principal principal

    The current web object to be processed.

    System.Int32 leafBreadthLimit

    Skip further visiting on this branch if the number of child items or documents with unique role assignments exceeded leafBreadthLimit. When setting to 0, the process will stop at list / document library level.

    Returns
    IEnumerable<RoleAssignmentEntity>

    Returns all role assignments

    GetSharingCapabilitiesTenant(Web, Uri)

    Get the external sharing settings for the provided site. Only works in Office 365 Multi-Tenant

    Declaration
    public static string GetSharingCapabilitiesTenant(this Web web, Uri siteUrl)
    Parameters
    Web web

    Tenant administration web

    Uri siteUrl

    Site to get the sharing capabilities from

    Returns
    System.String

    Sharing capabilities of the site collection

    GroupExists(Web, String)

    Checks if a group exists

    Declaration
    public static bool GroupExists(this Web web, string groupName)
    Parameters
    Web web

    Web to operate against

    System.String groupName

    Name of the group

    Returns
    System.Boolean

    True if the group exists, false otherwise

    IsUserInGroup(Web, String, String)

    Checks if a user is member of a group

    Declaration
    public static bool IsUserInGroup(this Web web, string groupName, string userLoginName)
    Parameters
    Web web

    Web to operate against

    System.String groupName

    Name of the group

    System.String userLoginName

    Loginname of the user

    Returns
    System.Boolean

    True if the user is in the group, false otherwise

    RemoveAdministrator(Web, UserEntity)

    Removes an administrators from the site collection

    Declaration
    public static void RemoveAdministrator(this Web web, UserEntity admin)
    Parameters
    Web web

    Site to operate on

    UserEntity admin

    UserEntity that describes the admin to be removed

    RemoveGroup(Web, Group)

    Remove a group

    Declaration
    public static void RemoveGroup(this Web web, Group group)
    Parameters
    Web web

    Web to operate against

    Group group

    Group object to remove

    RemoveGroup(Web, String)

    Remove a group

    Declaration
    public static void RemoveGroup(this Web web, string groupName)
    Parameters
    Web web

    Web to operate against

    System.String groupName

    Name of the group

    RemovePermissionLevelFromGroup(SecurableObject, String, RoleType, Boolean)

    Removes a permission level from a group

    Declaration
    public static void RemovePermissionLevelFromGroup(this SecurableObject securableObject, string groupName, RoleType permissionLevel, bool removeAllPermissionLevels = false)
    Parameters
    SecurableObject securableObject

    Web/List/Item to operate against

    System.String groupName

    name of the group

    RoleType permissionLevel

    Permission level to remove. If null all permission levels are removed

    System.Boolean removeAllPermissionLevels

    Set to true to remove all permission level.

    RemovePermissionLevelFromGroup(SecurableObject, String, String, Boolean)

    Removes a permission level from a group

    Declaration
    public static void RemovePermissionLevelFromGroup(this SecurableObject securableObject, string groupName, string roleDefinitionName, bool removeAllPermissionLevels = false)
    Parameters
    SecurableObject securableObject

    Web/List/Item to operate against

    System.String groupName

    name of the group

    System.String roleDefinitionName

    Name of the role definition to add, Full Control|Design|Contribute|Read|Approve|Manage Heirarchy|Restricted Read. Use the correct name of the language of the site you are using

    System.Boolean removeAllPermissionLevels

    Set to true to remove all permission level.

    RemovePermissionLevelFromPrincipal(SecurableObject, Principal, RoleType, Boolean)

    Removes a permission level from a user

    Declaration
    public static void RemovePermissionLevelFromPrincipal(this SecurableObject securableObject, Principal principal, RoleType permissionLevel, bool removeAllPermissionLevels = false)
    Parameters
    SecurableObject securableObject

    Web/List/Item to operate against

    Principal principal

    Principal to remove permission from

    RoleType permissionLevel

    Permission level to remove. If null all permission levels are removed

    System.Boolean removeAllPermissionLevels

    Set to true to remove all permission level.

    RemovePermissionLevelFromPrincipal(SecurableObject, Principal, String, Boolean)

    Removes a permission level from a user

    Declaration
    public static void RemovePermissionLevelFromPrincipal(this SecurableObject securableObject, Principal principal, string roleDefinitionName, bool removeAllPermissionLevels = false)
    Parameters
    SecurableObject securableObject

    Web/List/Item to operate against

    Principal principal

    Principal to remove permission from

    System.String roleDefinitionName

    Name of the role definition to add, Full Control|Design|Contribute|Read|Approve|Manage Heirarchy|Restricted Read. Use the correct name of the language of the site you are using

    System.Boolean removeAllPermissionLevels

    Set to true to remove all permission level.

    RemovePermissionLevelFromUser(SecurableObject, String, RoleType, Boolean)

    Removes a permission level from a user

    Declaration
    public static void RemovePermissionLevelFromUser(this SecurableObject securableObject, string userLoginName, RoleType permissionLevel, bool removeAllPermissionLevels = false)
    Parameters
    SecurableObject securableObject

    Web/List/Item to operate against

    System.String userLoginName

    Loginname of user

    RoleType permissionLevel

    Permission level to remove. If null all permission levels are removed

    System.Boolean removeAllPermissionLevels

    Set to true to remove all permission level.

    RemovePermissionLevelFromUser(SecurableObject, String, String, Boolean)

    Removes a permission level from a user

    Declaration
    public static void RemovePermissionLevelFromUser(this SecurableObject securableObject, string userLoginName, string roleDefinitionName, bool removeAllPermissionLevels = false)
    Parameters
    SecurableObject securableObject

    Web/List/Item to operate against

    System.String userLoginName

    Loginname of user

    System.String roleDefinitionName

    Name of the role definition to add, Full Control|Design|Contribute|Read|Approve|Manage Heirarchy|Restricted Read. Use the correct name of the language of the site you are using

    System.Boolean removeAllPermissionLevels

    Set to true to remove all permission level.

    RemoveUserFromGroup(Web, Group, User)

    Removes a user from a group

    Declaration
    public static void RemoveUserFromGroup(this Web web, Group group, User user)
    Parameters
    Web web

    Web to operate against

    Group group

    Group object to operate against

    User user

    User object that needs to be removed

    RemoveUserFromGroup(Web, String, String)

    Removes a user from a group

    Declaration
    public static void RemoveUserFromGroup(this Web web, string groupName, string userLoginName)
    Parameters
    Web web

    Web to operate against

    System.String groupName

    Name of the group

    System.String userLoginName

    Loginname of the user

    Back to top PnP Framework
    Generated by DocFX with Material UI
    spacer