Creating a Custom Expiration Formula Based On Metadata in SharePoint Server 2007 (Part 1 of 2)
Summary: Learn how to extend the existing expiration policy feature in Microsoft Office SharePoint Server 2007 by creating a policy resource to implement a custom expiration formula.
Applies to: 2007 Microsoft Office System, Microsoft Office SharePoint Server 2007
SharePoint Products and Technologies provide an extensible framework for implementing and extending policy features for information management policies. The existing policy features in Microsoft Office SharePoint Server 2007 provide functionality for document bar codes, document labels, auditing, and expiration. In this Microsoft Office Visual How To, you learn how you can extend the existing expiration policy feature by creating a policy resource to implement a custom expiration formula.
The first step in creating a custom expiration formula is to reference the Microsoft.SharePoint and Microsoft.Office.Policy assemblies in your project, as shown in the following code example. The Microsoft.Office.Policy assembly provides access to the Microsoft.Office.RecordsManagement namespace and the Microsoft.Office.RecordsManagement.Policy namespace.
The next step is to create a class that derives from the IExpirationFormula interface in the Microsoft.Office.RecordsManagement.Policy namespace. In this class, you need one public method named ComputeExpireDate. This method accepts an SPListItem object and an XMLNode object, and it returns a nullable DateTime object. This class is invoked when the custom formula is executed. In this example, the logic is very simple and returns a DateTime object set to Now. This logic is extended to meet a specific scenario in Creating a Custom Expiration Formula Based On Metadata in SharePoint Server 2007 (Part 2 of 2).
To make this class available for use in Office SharePoint Server 2007, you must compile it with a strong name and put in a location from which it can be accessed, such as in the global assembly cache or in the
To prepare the custom formula class so it can be used by the expiration policy feature, you must describe it as a policy resource and add it to the collection of available policy resources. In this example, you use a PowerShell script to perform these actions. The Microsoft.Office.Policy assembly is used and is loaded by the script. Next, you create an XML string to describe the policy resource. The PolicyResource element contains attributes for the following:
The XML string contains information for the name and description of the policy resource, and also information about the assembly and class. Before you add this policy resource to the collection, you validate the PolicyResource xml string by using the ValidateManifest method in the PolicyResource class. You then add the policy resource to the collection of policy resources by using the Add method of the PolicyResourceCollection class.
The result is that your expiration formula is made available to the expiration policy feature as a policy resource and is visible to users when creating a new expiration policy on a list of content types.
Figure 1. Custom expiration for new policy
The final step is to test things to make sure the custom expiration formula is properly registered and can be invoked. To do this, create an expiration policy on a library, as follows.
To create an expiration policy on a library
The expiration policy feature is part of the information management policy functionality provided by Microsoft Office SharePoint Server 2007. The expiration policy feature defines rules for how long content is retained and the action that occurs when the retention period expires. This Microsoft Office Visual How To shows how to extend the expiration formula by creating a policy resource and making it available to the expiration policy feature. In addition, you can also extend the expiration action.
An alternative approach to the custom expiration formula and action is to create a timer job to perform the calculation and action. However, implementing a timer job that evaluates and takes action on every item is not an easy development task. By using a custom formula, you can take advantage of the information-management policy infrastructure, which has already solved this problem.
This example shows how to use a PowerShell script to describe the functionality as a policy resource, and then add the resource to the collection of policy resources that are available in the records center. You can also remove the resource from the policy resource collection in a PowerShell script by calling the Delete method of the PolicyResourceCollection class, passing in the fully qualified class name of the policy resource, as shown here.
Although PowerShell scripts are used here, you should use best practices when deciding how to deploy this functionality to an environment outside of a single development computer. You can convert the functionality in these scripts to Microsoft Visual C# or Microsoft Visual Basic and use it in callout code of a SharePoint Feature.
Video Length: 00:06:04
File Size: 4.68 MB WMV