Sunday, 15 July 2012

“Learn SharePoint from SharePoint” is the principal theme of learning SharePoint
for me because what SharePoint says us to do for creating any SharePoint artifact,
SharePoint itself does same too. Just have a detailed look at SharePointRoot (14,
12) folder and you will find many working examples there…

Nowadays, I am using Visual Studio 2010 and its development capabilities to facilitate
my learning. I will showcase it in this post. Role of Visual Studio in SharePoint
development is sadly decreasing. Sometimes it’s not needed to open VS for days or
even whole week to complete my development activities. I am not a techie coder but
I love VS and it saddens me seeing my beloved VS loosening its hold in SharePoint
development. I just can hope Microsoft not eliminating VS as a development tool
in future SharePoint versions. I do not want something I love to go away again….nobody
will…

In my attempts to give me chance to open VS, I decided to write some code to create
custom Information Management Policies for the content type/ list. As usual I started
reading the blogs about creating custom retention/ expiration policies, custom policy
formula, custom policy actions. I found two excellent code examples at below links

In SharePoint, I always try to accomplish things declaratively rather than programmatically.
However, I was wondering whether there is any way to create a custom retention policy
declaratively rather than programmatically. I didn't find any declarative example
in my extensive googling. Hence I decided to give a try myself and to my surprise
I was successful too….all credits to reverse engineering capabilities of VS 2010.
Here are the steps.

13.Go to
the Site content type gallery and check the Information Management Policy Settings
of ItemWithPolicy content type. It
should have a custom Retention policy created and it will be exactly same as that
of created in step 2.

Easy it is! I created multiple examples of this (multiple retention stages, policy
with schedule, auditing policy). They can be downloaded from here.

Important Notes:

1.I was able to declaratively create custom policies for the Site Content types
only (content types present in Site Column gallery). Same was not true for the policies
created directly on List Content Types. Information management policy settings page
of such list content types gave me below error.

To me, this is a product bug. Even though I have not tried, I think creating List
content type based policies programmatically should be possible.

2.Declaratively policies can be created when Source of Retention for a list
is set to Content Type (see figure 5).

Figure 5: List's Information management policy settings page

You will need to programmatically create custom policies when retention source is
List or Folder. Declaratively there is no way. I am thinking that the reason is
Content type does have xmldocument
tag to declare custom policies but list schema does not have any such tags where
policies can be defined.

3.This method also add event receivers and few columns to the content type. Do not remove them. I have seen SharePoint code (Mircosoft.Office.Policy.dll) in which I noticed that those columns are used. Same will be the case of event receivers.