SPPermissionCollection class
NOTE: This API is now obsolete.
請改用新的SPRoleDefinition和SPRoleAssignment類別,來定義角色,並將使用者指派給它們。如需詳細資訊,請參閱Changes in the Authorization Object Model。(在Windows SharePoint Services 2.0, SPRole表示SPPermission物件的集合和維護回溯相容性。)
Inheritance hierarchy
System.Object
Microsoft.SharePoint.Administration.SPAutoSerializingObject
Microsoft.SharePoint.SPBaseCollection
Microsoft.SharePoint.SPPermissionCollection
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
<ObsoleteAttribute("Use the SPRoleAssignmentCollection class instead")> _
Public Class SPPermissionCollection _
Inherits SPBaseCollection
'用途
Dim instance As SPPermissionCollection
[ObsoleteAttribute("Use the SPRoleAssignmentCollection class instead")]
public class SPPermissionCollection : SPBaseCollection
備註
使用的SPList或SPWeb類別的Permissions屬性,傳回的清單或網站的使用權限集合。若要建立的使用權限,使用的Add或AddCollection的SPPermissionCollection方法。
若要從集合傳回單一的權限使用索引子。例如,如果集合指派給一個名為collPermissions變數中,使用在 C# 的collPermissions[index]或在 Visual Basic,其中index是使用權限集合中的索引編號,或是使用者或群組有 [清單] 或 [網站] 權限的SPMember物件的collPermissions(index) 。
Examples
下列程式碼範例會使用SPPermissionCollection類別,來顯示名稱] 和 [存取權指定清單的每個使用者的權限。此範例會逐一查看的站台的所有使用者,直到清單 ; 所有的權限如果使用者識別碼符合清單權限的成員 ID,則會顯示使用者的資訊。
這個範例要求using指示詞 (在 Visual Basic 的Imports ) **[Microsoft.SharePoint]和[Microsoft.SharePoint.Utilities]**命名空間。
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 user As SPUser
For Each user In users
Dim perm As SPPermission
For Each perm In perms
If user.ID = perm.Member.ID Then
Response.Write("User: " & SPEncode.HtmlEncode(user.Name) _
& " Permissions: " & perm.PermissionMask.ToString()
& "<BR>")
End If
Next perm
Next user
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;
foreach (SPUser oUser in collUsers)
{
foreach (SPPermission oPermission in collPermissions)
{
if (oUser.ID == oPermission.Member.ID)
{
Response.Write("User: " +
SPEncode.HtmlEncode(oUser.Name) +
" Permissions: " +
oPermission.PermissionMask.ToString() +
"<BR>");
}
}
}
}
注意事項 |
---|
某些物件實作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.