<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>Agile SharePoint Development by 21apps - Latest Comments in Create Custom Policy programmatically</title><link>http://21apps.disqus.com/</link><description>Agile SharePoint Development covering all aspects from Scrum, Unit Testing, TDD, Continuos Build, Peformance tuning - in fact anything and everything to do with Agile SharePoint Development.</description><language>en</language><lastBuildDate>Mon, 27 Oct 2008 08:14:26 -0000</lastBuildDate><item><title>Re: Create Custom Policy programmatically</title><link>http://www.21apps.com/sharepoint/create-custom-policy-programmatically/#comment-6671579</link><description>Ven,&lt;br&gt;The reason is probably due to you not setting any policy bindings, as in the post example:-&lt;br&gt;&lt;br&gt;policy.PolicyRoleBindings.Add(oWebApplication.PolicyRoles.GetSpecialRole(SPPolicyRoleType.FullControl));</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Andrew Woodward</dc:creator><pubDate>Mon, 27 Oct 2008 08:14:26 -0000</pubDate></item><item><title>Re: Create Custom Policy programmatically</title><link>http://www.21apps.com/sharepoint/create-custom-policy-programmatically/#comment-6671578</link><description>Hi,&lt;br&gt;   I am trying to get the users from the "Policy of Web Application" in Central Administration through Object Model &lt;br&gt;&lt;br&gt;and also trying to add users to the same Policy through object model. I am using the following code to achieve &lt;br&gt;&lt;br&gt;this. But I am getting an "Object Reference Not Set to an Instance of an Object" exception when I am trying to call &lt;br&gt;&lt;br&gt;the Update Method of the SPWebApplication object.&lt;br&gt;Please help me. The strange thing happening here is,when I am trying to add the users to the WebApplication policy, &lt;br&gt;&lt;br&gt;the users are getting added to though the update fails. The next time when I debug the application, I do see the &lt;br&gt;&lt;br&gt;new users added though the update failed. Moreover, I am not able to see the newly added users in the "Policy For &lt;br&gt;&lt;br&gt;Web Application" section of the Central Administration. Can anyone please help me out. Here is the code which I am &lt;br&gt;&lt;br&gt;using to achieve this.&lt;br&gt;&lt;br&gt;SPFarm farm = SPFarm.Local;   &lt;br&gt;SPWebService service = farm.Services.GetValue("");   &lt;br&gt;foreach(SPWebApplication webApp in service.WebApplications)   &lt;br&gt;{   &lt;br&gt;  if(webApp.Name == "My Web App")   &lt;br&gt;        {   &lt;br&gt;            webApp.ZonePolicies(SPUrlZone.Default).Add("username","displayname");   &lt;br&gt;            webApp.Update();  // I am getting the Object Reference error at this line   &lt;br&gt;        }   &lt;br&gt;}   &lt;br&gt;  &lt;br&gt;&lt;br&gt;Please help me ASAP.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ven</dc:creator><pubDate>Sun, 26 Oct 2008 00:39:29 -0000</pubDate></item></channel></rss>