If you enable or disable Expiration Policy using SharePoint API, it is little bit complicated.
Expiration Policy including Information Management Policy features is associated list's ContentType. (not list of itself)
You can see how to enable and create Expiration Policy in bellow blog post.
Using the SharePoint API to Configure an Expiration Policy on a Document Library
If you delete and disable Expiration Policy, please see bellow program code.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; using Microsoft.Office.RecordsManagement.InformationPolicy; namespace ConsoleApplication3 { class Program { private const string expirationPolicyFeatureId = "Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration"; static void Main(string[] args) { SPSite site = new SPSite("http://sp2010"); SPWeb web = site.OpenWeb(); SPList list = web.Lists["Annnounce03"]; foreach (SPContentType contentType in list.ContentTypes) { Policy policy = Policy.GetPolicy(contentType); if (policy != null) { //delete Expiration Policy on the List policy.Items.Delete(expirationPolicyFeatureId); } } } } }
Tips :
- You need to add Reference Microsoft.Office.Policy.dll from /14/ISAPI.
- Expiration Policy is defined as Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.
Very informative post. I sometimes do presentations on SharePoint and was wondering if I could use your Print List example in my presentations and refer my audience to your website for further info.
ReplyDelete