Поделиться через


SPPermissionCollection Class

The SPPermissionCollection class represents a collection of SPPermission objects.

System.Object

   Microsoft.SharePoint.SPBaseCollection

      Microsoft.SharePoint.SPPermissionCollection

Public Methods

The following table shows the public methods of the SPPermissionCollection class and a brief description of each.

Name Description
Add Creates a permission object with the specified member and permissions in the collection.
AddCollection Adds a collection of permissions to the collection based on arrays that specify user information, user permissions, cross-site group names, cross-site group permissions, site group names, and site group permissions.
CheckPermissions Verifies whether the current user has the specified permissions for the list or site and, if not, throws an Access Denied exception.
DoesUserHavePermissions Returns a Boolean value that indicates whether the current user has the specified permissions for the list or site.
Remove(Int32) Removes the permission object at the given index in the collection.
Remove(Microsoft.SharePoint.SPMember) Removes the permission associated with the specified member from the collection.
RemoveCollection Removes the permissions represented by an integer array of member IDs from the collection.
ResetPermissions Resets the permissions inherited from the parent object.

Public Properties

The following table shows the public properties of the SPPermissionCollection class, the data type of each property, and a brief description of each.

Name Data Type Description
Count Int32 Gets the number of permissions in the collection.
Inherited Boolean Gets a Boolean value that specifies whether the collection is inherited from the parent object.
Item(Int32) Microsoft.SharePoint.SPPermission Gets the permission object at the specified index in the collection.
Item(Microsoft.SharePoint.SPMember) Microsoft.SharePoint.SPPermission Gets the permission object with the specified member from the collection.
Parent Object Gets the parent object for the collection of permissions, which can be a list or a site.
RequestAccess Boolean Gets or sets a Boolean value that specifes whether request for access is enabled for a list.
RequestAccessEmail String Gets or sets whether request for access is enabled for a site and specifies the e-mail address to which requests are sent.
Xml String Gets the collection of permissions in XML format.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread safe.

Remarks

Use the Permissions property of either the SPWeb or SPList class to return the collection of permissions for a list or a site. To create a permission, use either the Add or AddCollection method represented in the table above.

Use an indexer to return a single permission from the collection. For example, if the collection is assigned to a variable named myPermissions, use myPermissions[index] in C#, or myPermissions(index) in Visual Basic .NET, where index is either the index number of the permission in the collection or the SPMember object for a user or site group that has the permission for the list or site.

Example

The following code example uses the SPPermissionCollection class to display the name and permissions for each user who has access to a specified list. The example iterates through all the users of a site and through all the permissions for a list, and if a user ID matches the member ID of a list permission, information for the user is displayed.

This example requires using directives (Imports in Visual Basic) for the Microsoft.SharePoint, Microsoft.SharePoint.Utilities, and Microsoft.SharePoint.WebControls namespaces.

Requirements

Namespace: Microsoft.SharePoint

Platforms: Microsoft Windows Server 2003

Assembly: Windows SharePoint Services (in Microsoft.SharePoint.dll)

Security: Code Access Security