How to Disable an Expiration Policy (Retention) on a List Using SharePoint Object Model

We usually use Expiration Policy (Retention) in Information Management Policy features. Expiration Policy enables to set expiration date for each item in a list. The item will be deleted when expiration date will come.

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

Tips :
- You need to add Reference Microsoft.Office.Policy.dll from /14/ISAPI.
- Expiration Policy is defined as Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.

1 comment:

  1. 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.