[转]Adding a custom action to the MOSS expiration policy

Adding a custom action to the MOSS expiration policy

Office SharePoint 2007 out of the box has a policy framework, that can help with information management in your organization. On of the out of the box policies is the expiration policy. You can setup a policy for a site collection, content type of SharePoint List that will expire your item after a certain number of days, months or years after one of the date field values in your item. You can expire all whitepapers for example 5 years after they have been last modified.
expire1

The action to SharePoint will perform when the item expires depends on you, Out of the box there are 2 options: The items is deleted or a workflow is started. If a workflow is available for the content type or list, it will be listed in the dropdown.
expire2

It is also possible to create your own actions. After you have created and registered your action, it will show up in the “Perform this action” dropdown in the screenshot above.

Step 1 – Implement the interface

To create a custom action, you need to implement the IExpirationAction interface that can be found in the namespace Microsoft.Office.RecordsManagement.Features.

 
               
    public class ExpirationSendWarning : IExpirationAction 
    {
        public void OnExpiration(Microsoft.SharePoint.SPListItem item, 
            System.Xml.XmlNode parametersData, DateTime expiredDate)
        {
            // Do whatever you need to do with you item when it expires
        }
    }

You need to put this in a strong named assembly and add it to the GAC.

Step 2 – Create the registration xml

After creating the expiration action, you need to register it by creating an xml file. You will find an example below. The featureId attribute of the PolicyResource element is important. This needs to be the ID of the out of the box expiration policy. The rest is pretty clear.  Save this xml to a file called “actionmanifest.xml”

    <?xml version="1.0" encoding="utf-8" ?>
    <p:PolicyResource id="TST.POC.PolicyFeatures.ExpirationSendWarning"
          featureId="Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration"
          type="Action"  xmlns:p="urn:schemas-microsoft-com:office:server:policy">
      <p:LocalizationResources>dlccore</p:LocalizationResources>
      <p:Name>ExpirationSendWarning</p:Name>
      <p:Description>Sends a warning on the reminder date</p:Description>
      <p:Publisher>Ton Stegeman</p:Publisher>
      <p:AssemblyName>
        TST.POC.PolicyOfTruth, Version=1.0.0.0, Culture=neutral,
        PublicKeyToken=503edd7b21a430b3
      </p:AssemblyName>
      <p:ClassName>TST.POC.PolicyFeatures.ExpirationSendWarning</p:ClassName>
    </p:PolicyResource>

Step 3 – Register the expiration action

The last step is to register the action. To do that, you run the example piece of code below from any type of application you like best:

 
               
    string actionmanifest = System.IO.File.ReadAllText("actionmanifest.xml");
    PolicyResourceCollection.Add(actionmanifest);

The PolicyResourceCollection can be found in the namespace “Microsoft.Office.RecordsManagement.InformationPolicy”. Both for step 1 and 3 you need a reference to Microsoft.Office.Policy.dll

转载于:https://www.cnblogs.com/frankzye/archive/2010/08/17/1801535.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值