Improve Your Technology

Just another blog for techology

Retention Policies in SharePoint 2010 – 2

Custom Retention Policy

C#.NET Logic

Writing logic for Retention policy is very simple. Follow below steps and you are able to create a custom policy for your application.

1.       Create an empty SharePoint project using visual studio 2008 or 2010. Make sure that you have select 3.5 .net frame work.

2.       Add “Microsoft.Office.Policy” dll reference to the project.

3.       Include below namespaces in the code.

using Microsoft.Office.RecordsManagement;

using Microsoft.Office.RecordsManagement.PolicyFeatures;

4.       Copy paste below sample code in the class file. And write your own logic in the “Logic to calculate expiration date” section. You can write anything you want.

public class CustomExpiration : IExpirationFormula

    {

        public Nullable<DateTime> ComputeExpireDate(SPListItem item, System.Xml.XmlNode parametersData)

                {

                    DateTime? expirationDate = null;

                    //Logic to calculate expiration date

            return expirationDate;

        }

    }

5.       Add new xml item to the project and name the file as “Policy.xml”

6.       Copy paste below XML data into that file. Name the namespace, class name, GUID and DLL name properly

<?xml version=”1.0″ encoding=”utf-8″ ?>

<PolicyResource

xmlns=”urn:schemas-microsoft-com:office:server:policy”

id = “CustomPolicy.CustomExpiration”

featureId=”Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration”

type = “DateCalculator”>

  <Name>Custom Expiration</Name>

  <Description>Custom user expiration policy</Description>

  <AssemblyName>

    CustomPolicy, Version=1.0.0.0, Culture=neutral,PublicKeyToken=b24234a72f512306

  </AssemblyName>

  <ClassName>CustomPolicy.CustomExpiration</ClassName>

</PolicyResource>

 

7.       Build the solution and create a package and deploy in the SharePoint central administration.

Configuring custom retention policy

Refer Basic retention policies link to know preliminary steps.

After deploying the custom feature in the SharePoint, “Set by custom retention formula installed on this server” option will be enabled.

8.       Select custom retention policy that you have created and click “Ok”.

January 6, 2012 Posted by | Custom Retention Policy, SharePoint 2010, Technology | , | 2 Comments