SPRoleCollection.Add method
NOTE: This API is now obsolete.
Obsolete. Use the new SPRoleDefinition and SPRoleAssignment classes instead, to define roles and to assign users to them. For more information, see Authorization object model. (In Windows SharePoint Services 2.0, the Add method created a role object with the specified name, description, and permission mask in the collection and is maintained for backward compatibility.)
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'Declaration
<ObsoleteAttribute("Use the SPRoleDefinitionCollection class instead")> _
Public Sub Add ( _
name As String, _
description As String, _
permissionMask As SPRights _
)
'Usage
Dim instance As SPRoleCollection
Dim name As String
Dim description As String
Dim permissionMask As SPRights
instance.Add(name, description, permissionMask)
[ObsoleteAttribute("Use the SPRoleDefinitionCollection class instead")]
public void Add(
string name,
string description,
SPRights permissionMask
)
Parameters
name
Type: System.StringA string that contains the name of the role.
description
Type: System.StringA string that contains the description of the role.
permissionMask
Type: Microsoft.SharePoint.SPRightsAnSPRightsvalue that specifies rights for the permission mask.
Remarks
To define a permission mask for a user or group that consists of multiple rights, use the pipe symbol ("|") in Microsoft Visual C# or Or in Microsoft Visual Basic to delimit the rights.
Examples
The following code example adds a role that has permissions to manage both the site and its subsites.
Dim site As SPWeb =
SPContext.Current.Site.AllWebs("Site_Name")
Dim roles As SPRoleCollection = site.Roles
roles.Add("Role_Name", "Description", SPRights.ManageWeb _
Or SPRights.ManageSubwebs)
using(SPWeb oWebsite = SPContext.Current.Site.AllWebs["Site_Name"])
{
SPRoleCollection collRoles = oWebsite.Roles;
collRoles.Add("Role_Name", "Description", SPRights.ManageWeb |
SPRights.ManageSubwebs);
}
Note
Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.