Friday, January 14, 2011

Create a policy for Content type programmatically in Sharepoint 2010

using (SPSite siteCollection = new SPSite("suryasite")) { using (SPWeb web = siteCollection.OpenWeb()) { string strFeatureID = "Microsoft.Office.RecordsManagement.PolicyFeatures.PolicyAudit"; SPList list = web.Lists["Test2"]; SPContentType listctype = list.ContentTypes["CustomTemplate1"]; //listctype. // Microsoft.Office.RecordsManagement.PolicyFeatures.PolicyAudit Policy policyAudit = Policy.GetPolicy(listctype); if (policyAudit == null) // if (!policyAudit.Equals("CustomTemplate1")) { Policy.CreatePolicy(listctype, null); policyAudit = Policy.GetPolicy(listctype); policyAudit.Name = "OPS Audit Policy"; policyAudit.Statement = "OPS Audit on Project Documents content type"; //string.Format("Audits Edit/Delete/Restore {0} items", Helper.PREFIX); policyAudit.Description = policyAudit.Statement; if (policyAudit.Items[strFeatureID] == null) { string strCustomData = ""; policyAudit.Items.Add(strFeatureID, strCustomData); } } } }

No comments:

Post a Comment

Followers