SPPolicyCollection class
代表SPPolicy物件的集合。
Inheritance hierarchy
System.Object
Microsoft.SharePoint.Administration.SPAutoSerializingObject
Microsoft.SharePoint.Administration.SPPolicyCollection
Namespace: Microsoft.SharePoint.Administration
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class SPPolicyCollection _
Inherits SPAutoSerializingObject _
Implements IEnumerable
'用途
Dim instance As SPPolicyCollection
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class SPPolicyCollection : SPAutoSerializingObject,
IEnumerable
備註
區域原則是原則物件的集合。每個使用者或群組指派的個別原則物件。
使用SPWebApplication類別之Policies屬性可傳回 Web 應用程式的原則的集合,或使用SPWebApplication類別之ZonePolicies方法可傳回指定之區域的原則的集合。
若要建立原則,請執行下列步驟:
若要建立集合中的 Web 應用程式的原則原則物件使用Add方法。
若要建立的 Web 應用程式的原則角色集合內的原則角色物件使用SPPolicyRoleCollection類別之Add方法。
使用SPPolicy.SPPolicyRoleBindingCollection類別之Add方法將新的原則角色新增至集合的新原則繫結。
呼叫Update類別的方法SPWebApplication的變更才會生效。
若要從集合中傳回單一原則使用索引器。例如,若集合已指派給變數myPolicies,使用myPolicies[index]以 C# 或 Visual Basic,其中index是名稱或索引編號集合中的原則中的myPolicies(index) 。
Examples
下列範例會建立新的原則中指定的 Web 應用程式的原則的集合。
Dim uri = New Uri("http://MyServer")
Dim webApplication As SPWebApplication = SPWebApplication.Lookup(uri)
Dim policyCollection As SPPolicyCollection = webApplication.Policies
Dim policyRoles As SPPolicyRoleCollection = webApplication.PolicyRoles
Dim policy As SPPolicy = policyCollection.Add("UserAlias", "MyPolicy")
Dim policyRole As SPPolicyRole = policyRoles.Add("MyPolicyRole", "My description.", SPBasePermissions.ViewPages Or SPBasePermissions.ViewListItems, SPBasePermissions.AddAndCustomizePages Or SPBasePermissions.AddListItems)
policy.PolicyRoleBindings.Add(policyRole)
webApplication.Update()
System.Uri uri = new Uri("http://MyServer");
SPWebApplication webApplication = SPWebApplication.Lookup(uri);
SPPolicyCollection policyCollection = webApplication.Policies;
SPPolicyRoleCollection policyRoles = webApplication.PolicyRoles;
SPPolicy policy = policyCollection.Add("UserAlias","MyPolicy");
SPPolicyRole policyRole = policyRoles.Add("MyPolicyRole", "My description.", SPBasePermissions.ViewPages | SPBasePermissions.ViewListItems, SPBasePermissions.AddAndCustomizePages | SPBasePermissions.AddListItems);
policy.PolicyRoleBindings.Add(policyRole);
webApplication.Update();
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.