-
Website
http://www.21apps.com/ -
Original page
http://www.21apps.com/sharepoint/create-custom-policy-programmatically/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
laurarogers
1 comment · 1 points
-
AndrewWoody
31 comments · 1 points
-
Zimmergren
2 comments · 1 points
-
prepbooks
1 comment · 4 points
-
deep_k_sharma
1 comment · 1 points
-
-
Popular Threads
I am trying to get the users from the "Policy of Web Application" in Central Administration through Object Model
and also trying to add users to the same Policy through object model. I am using the following code to achieve
this. But I am getting an "Object Reference Not Set to an Instance of an Object" exception when I am trying to call
the Update Method of the SPWebApplication object.
Please help me. The strange thing happening here is,when I am trying to add the users to the WebApplication policy,
the users are getting added to though the update fails. The next time when I debug the application, I do see the
new users added though the update failed. Moreover, I am not able to see the newly added users in the "Policy For
Web Application" section of the Central Administration. Can anyone please help me out. Here is the code which I am
using to achieve this.
SPFarm farm = SPFarm.Local;
SPWebService service = farm.Services.GetValue("");
foreach(SPWebApplication webApp in service.WebApplications)
{
if(webApp.Name == "My Web App")
{
webApp.ZonePolicies(SPUrlZone.Default).Add("username","displayname");
webApp.Update(); // I am getting the Object Reference error at this line
}
}
Please help me ASAP.
The reason is probably due to you not setting any policy bindings, as in the post example:-
policy.PolicyRoleBindings.Add(oWebApplication.PolicyRoles.GetSpecialRole(SPPolicyRoleType.FullControl));