Friday, October 26, 2012

Expiration Date Not Updating

This is an issue that affected a large number of document libraries in my environment. I have retention policies set on documents that are based on the modified date, yet for many documents the expiration date was not getting updated, or in some cases not getting set at all.  As you can see in this photo, the expiration date on three of the documents was not updated, and six didn't have an expiration date at all.  Viewing compliance details showed the correct expiration date.
 
Without going into too much detail, the compliance details page calculates the expiration date on the fly based on the ItemRetentionFormula for the item.  The Expiration Date, however, is updated by an event receiver.  This is why you have to run a SystemUpdate() on all documents after you enable retention policies.
 
I found that the event receivers were missing from these document libraries. How did this happen with a few of the documents having an Expiration Date?  I don't know, but I do know how to add them back.
 
Luckily, adding the event receivers is very easy to do with a bit of code. For each of the event types you just have to run this code:
list.EventReceivers.Add(SPEventReceiverType.ItemAdded, "Microsoft.Office.Policy, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c", "Microsoft.Office.RecordsManagement.Internal.UpdateExpireDate");
list.Update();
 
Here's the entire piece of code that creates a command line tool to update a library

No comments:

Post a Comment