SPRoleCollection.GetSpecialRole 方法

请注意:此 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 GetCollection method returned a system role specified by its type and is maintained for backward compatibility.)

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
<ObsoleteAttribute("Use the SPRoleDefinitionCollection class instead")> _
Public Function GetSpecialRole ( _
    roleType As SPRoleType _
) As SPRole
用法
Dim instance As SPRoleCollection
Dim roleType As SPRoleType
Dim returnValue As SPRole

returnValue = instance.GetSpecialRole(roleType)
[ObsoleteAttribute("Use the SPRoleDefinitionCollection class instead")]
public SPRole GetSpecialRole(
    SPRoleType roleType
)

参数

返回值

类型:Microsoft.SharePoint.SPRole
一个表示该角色的SPRole对象。

示例

下面的代码示例使用GetSpecialRole方法将指定的用户添加到当前网站上的Reader角色。

此示例假定存在包含标签控件的 .aspx 页。

Dim site As SPWeb = SPContext.Current.Web
Dim roles As SPRoleCollection = site.Roles
Dim role As SPRole = roles.GetSpecialRole(SPRoleType.Reader)

role.AddUser("User_Name", "E-mail_Address", "User_Display_Name", 
    "Notes")
SPWeb oWebsite = SPContext.Current.Web;
SPRoleCollection collRoles = oWebsite.Roles;
SPRole oRole = collRoles.GetSpecialRole(SPRoleType.Reader);

oRole.AddUser("User_Name", "E-mail_Address", "User_Display_Name", 
    "Notes");

另请参阅

引用

SPRoleCollection 类

SPRoleCollection 成员

Microsoft.SharePoint 命名空间