Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

SPPolicyCollection class

Represents a collection of SPPolicy objects.

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.Administration.SPPolicyCollection

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

'Declaration
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class SPPolicyCollection _
	Inherits SPAutoSerializingObject _
	Implements IEnumerable
'Usage
Dim instance As SPPolicyCollection

The policy for a zone is a collection of policy objects. Each user or group is assigned a separate policy object.

Use the Policies property of the SPWebApplication class to return the collection of policies for a Web application, or use the ZonePolicies method of the SPWebApplication class to return the collection of policies for a specified zone.

To create a policy, perform the following steps:

  1. Use the Add method to create a policy object within the collection of policies for the Web application.

  2. Use the Add method of the SPPolicyRoleCollection class to create a policy role object within the collection of policy roles for the Web application.

  3. Use the Add method of the SPPolicy.SPPolicyRoleBindingCollection class to add the new policy role to the collection of policy bindings for the new policy.

  4. Call the Update method of the SPWebApplication class for changes to take effect.

Use an indexer to return a single policy from the collection. For example, if the collection is assigned to a variable named myPolicies, use myPolicies[index] in C#, or myPolicies(index) in Visual Basic, where index is either the name or the index number of the policy in the collection.

The following example creates a new policy within the collection of policies of a specified Web application.

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()

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