共用方式為


SPPermission class

NOTE: This API is now obsolete.

請改用新的SPRoleDefinitionSPRoleAssignment類別,來定義角色,並將使用者指派給它們。如需詳細資訊,請參閱Changes in the Authorization Object Model。(在Windows SharePoint Services 2.0, SPRole表示指派給使用者或群組清單或網站的權限和維護回溯相容性。)

Inheritance hierarchy

System.Object
  Microsoft.SharePoint.SPPermission

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'宣告
<ObsoleteAttribute("Use the SPRoleAssignment class instead")> _
Public Class SPPermission
'用途
Dim instance As SPPermission
[ObsoleteAttribute("Use the SPRoleAssignment class instead")]
public class SPPermission

備註

使用的SPListSPWeb類別的Permissions屬性,傳回SPPermissionCollection物件,表示清單或網站的權限的集合。若要從集合傳回單一的權限使用索引子。例如,如果集合指派給一個名為collPermissions變數中,使用在 C# 的collPermissions[index]或在 Visual Basic,其中index是使用權限集合中的索引編號,或是使用者或群組有 [清單] 或 [網站] 權限的SPMember物件的collPermissions(index) 。

使用權限是由右或由SPRights列舉型別所指定的權限的組合所組成。PermissionMask屬性包含指派給使用者或群組的權限集合。

Examples

下列程式碼範例會使用SPPermission類別的PermissionMask屬性,修改指派給單一使用者的權限。

Dim siteCollection As SPSite = SPContext.Current.Site
Dim site As SPWeb = siteCollection.AllWebs("Site_Name")
Dim list As SPList = site.Lists("List_Name")
Dim perms As SPPermissionCollection = list.Permissions
Dim users As SPUserCollection = site.Users

Dim member As SPMember = users("User_Name")

list.Permissions(member).PermissionMask = 
    SPRights.AddListItems Or SPRights.EditListItems
SPSite oSiteCollection = SPContext.Current.Site;
using(SPWeb oWebsite = oSiteCollection.AllWebs["Site_Name"])
{
    SPList oList = oWebsite.Lists["List_Name"];
    SPPermissionCollection collPermissions = oList.Permissions;
    SPUserCollection collUsers = oWebsite.Users;

    SPMember oMember = collUsers["User_Name"];

    oList.Permissions[oMember].PermissionMask = 
        SPRights.AddListItems | SPRights.EditListItems;
}
注意事項注意事項

某些物件實作IDisposable介面,並且您必須避免之後不再需要保留這些物件在記憶體中。良好的程式碼撰寫方式的相關資訊,請參閱Disposing Objects

Thread safety

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

請參閱

參照

SPPermission members

Microsoft.SharePoint namespace