请注意:此 API 现在已过时。
Obsolete. Use the new SPRoleDefinition and SPRoleAssignment classes instead, to define roles and to assign users to them. For more information, see Changes in the 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.)
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
<ObsoleteAttribute("Use the SPRoleDefinitionCollection class instead")> _
Public Sub Add ( _
name As String, _
description As String, _
permissionMask As SPRights _
)
用法
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
)
参数
name
类型:System.String一个字符串,包含角色的名称。
description
类型:System.String一个字符串,包含角色的说明。
permissionMask
类型:Microsoft.SharePoint.SPRightsSPRights值,该值指定权限的权限掩码。
备注
若要定义为用户或组,其中包括多个权限的权限掩码,使用 Microsoft Visual C# 或Or在 Microsoft Visual Basic 中的管道符号 ("|") 来分隔权限。
示例
下面的代码示例添加具有管理网站及其子网站的权限的角色。
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);
}
备注
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.