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

Advertisements

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

2 Comments »

  1. Hello,
    I am working on a barcode project using C# i.e generating the barcode,scanning it and printing it.I would like to use Barcode classes and methods which is available from Microsoft.Office.policy.dll.Can you please guide me in using these classes.Or if there is any other Api’s that i can use??Please help out.

    Comment by Akshay kumar | July 13, 2012 | Reply

    • I will try these classes and will let you know. Right now I don’t have idea on it.

      Comment by srinutamada | July 19, 2012 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: