Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a requirement to create a site collection policy (retention policy) programmatically. It can be either a powershell script or in C# using Visual Studio 2010. I did a lot of research and am not able to find a solution. Can anybody please help.

Thanks & Regards,

Vishnu

share|improve this question

3 Answers 3

The documentation is a little thin for creating retention policies. Hopefully this will get you started:

http://blogs.msdn.com/b/jfrost/archive/2011/03/15/setting-custom-expiration-programmatically.aspx

share|improve this answer

@SharePointer I am sure he is talking about the Content Type Policy Templates that are found below the "Site Collection Administration" section in the site settings page.

Sure thing you can use powershell to create these policies, here is an example:

http://sharepointpointer.blogspot.ca/2012/09/powershell-to-create-retention-policies.html

share|improve this answer

In SharePoint 2010 you can apply the retention policy to a content type, to a list or document library or to a folder.

Source

by reading that I don't think you can apply it to site collection, did you tried any procedure manually that you want to do using coding or script ?

EDIT

try this then

there is a Retention policy class at MSDN article

for example

 public static void AddPolicyToContentType()
 { 
            using(SPSite site = new SPSite("http://basesmcdev2/sites/tester1"))
            {
                using(SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["tester2"];
                    SPContentType ctype = list.ContentTypes["Document"];

                    if (Policy.CanHavePolicy(ctype))
                    {
                        PolicyCatalog pc = new PolicyCatalog(site);
                        var policy = (from p in pc.PolicyList.OfType<Policy>() where p.Name == "expireme" select p).First();
                        Policy.CreatePolicy(ctype, policy);
                        Policy.ProcessChanges(site);

                    }
                }

 }
share|improve this answer
    
I didnt mean to say I want to apply a policy to a site collection (Retention policy is one of the site collection policies). Please ignore the term 'site collection policy' if its confusing. I need to basically create a retention policy programmatically. –  Vishnu Sep 11 '12 at 11:15
    
The code that you have given, assigns a policy 'expireme' to a list and a content type. It doesnt create a policy. I need to be programmatically do the steps that are mentioned in the link - [link]office.microsoft.com/en-us/sharepoint-server-help/… –  Vishnu Sep 12 '12 at 1:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.