Partager via


AddCollection Method

The AddCollection method of the SPPermissionCollection class adds users and their permissions to a list, modifies the permissions of users for a list, modifies the permissions of an existing site or cross-site group for a list, or modifies the permissions of an existing site group for a site.

Parameters

addUsersInfo   A Microsoft.SharePoint.SPUserInfo array that specifies information about users, including user names, e-mail addresses, display names, and notes about the users.

addUsersPermissions   A Microsoft.SharePoint.SPRights array that specifies permissions for a user.

addGroupsNames   A string array that specifies the names of cross-site groups.

addGroupsPermissions   A Microsoft.SharePoint.SPRights array that specifies permissions for a cross-site group.

addRolesNames   A string array that specifies the names of site groups.

addRolesPermissions   A Microsoft.SharePoint.SPRights array that specifies permissions for a site group.

Remarks

The parameters for the AddCollection method work in pairs, one pair for adding or modifying users and their permissions, one pair for modifying the permissions of site groups, and one pair for modifying the permissions of cross-site groups. The number of elements contained in the arrays for each pair must match. Pass null for parameters that you do not intend to implement.

If you change the permissions of a user, site group, or cross-site group for a list, the user or group maintains the original permissions for the site. The changes apply only to the list. If you add users and permissions to a list but not to the site as a whole, the users acquire Guest permissions for the site.

Example

The following code example uses all six parameters of the AddCollection method to modify the permissions of site users for whom the Notes property contains 2, as well as to modify the list permissions for specified site groups and cross-site groups.

The example iterates twice through the collection of users for the specified site, once to count the number of users whose notes contain 2 and to use this number to set the size of the associated SPRights array, and once to assign each of these users to an SPUserInfo array.

The pipe symbol ("|") in C# or Or in Visual Basic .NET is used to delimit multiple rights for a single permission.

Requirements

Platforms: Microsoft Windows Server 2003

Security: Code Access Security