SPPolicyCollection Class
Collapse the table of content
Expand the table of content

SPPolicyCollection Class

Represents a collection of SPPolicy objects.


Namespace:  Microsoft.SharePoint.Administration
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No

[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class SPPolicyCollection : SPAutoSerializingObject, 

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.

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



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