I was wandering if someone could assist?

I am trying to implement a custom expiration policy within sharepoint, I hope to achieve the ability to get notified when a document reaches its expiration date via email.

I have been attempting to implement this with the following code:

using System.Web;
using Microsoft.SharePoint;
using Microsoft.Office.RecordsManagement;
using Microsoft.Office.RecordsManagement.PolicyFeatures;
using Microsoft.Office.DocumentManagement;
using Microsoft.SharePoint.Utilities;
using System;

namespace ExpirationTest
public class FilteredExpiration : IExpirationFormula
    public DateTime? ComputeExpiteDate(SPListItem item, System.Xml.XmlNode  parametersData)

        //Check if item is in warning period
        //If it is, send warning email stating
        //that document will expire in a month

        DateTime expiryDate = new DateTime();
        if (item["_dlc_ExpireDate"] != null)

            //Get item's expiry date.
            expiryDate = (DateTime)item["_dlc_ExpireDate"];

            //Find remaining time to expiry
            TimeSpan diff = expiryDate.Subtract(DateTime.Now);

            //If less then a month, send warning email
            if (diff.Minutes <= 2)


        if (item["CollectMe"].ToString().Equals("True"))
            return DateTime.Now;
            return ((DateTime)item["Modified"]).AddDays(365);


    private void SendWarningEmail(SPListItem item)
            SPSite thisSite = new SPSite("http://sharepoint:14236");
            SPWeb thisWeb = thisSite.RootWeb;
            string toField = "Alex.Nagy@centraxtcl.com";
            string subject = "Test Message";
            string body = "Document - " + item.Name + " - will expire in a month.";
            HttpContext oldContext = HttpContext.Current;
            HttpContext.Current = null;
            bool success = SPUtility.SendEmail(thisWeb, true, true, toField, subject, body);
            HttpContext.Current = oldContext;

        catch (Exception ex)
            //handle exception



When attempting to implement this code I get the following error:

Error 1 'ExpirationTest.FilteredExpiration' does not implement interface member 'Microsoft.Office.RecordsManagement.PolicyFeatures.IExpirationFormula.ComputeExpireDate(Microsoft.SharePoint.SPListItem, System.Xml.XmlNode)' C:\Users\Alex.Nagy\Documents\Visual Studio 2010\Projects\ExpirationTest\ExpirationTest\FilteredExpiration.cs 11 18 ExpirationTest

Can anyone help, or suggest an alternate way of doing this?

  • You probably should look at an alternative approach for sending email, eg a Workflow stage after this one. Only use the Expiration formula to calculate the DateTime to the next stage. You will end up with multiple emails, as this function is called from both the "Compliance Details" dialog and timer jobs to check and update expiration. – Daniel Symonds-Lloyd Apr 16 '12 at 9:47
  • So you would suggest keeping the custom expiration portion add then creating a workflow to send the expiration warning email? – Alex Nagy Apr 16 '12 at 9:51
  • Yes, as you have some custom logic to determine the next stage date (around CollectMe). Either use a workflow to send the email or write your own ExpirationAction. msdn.microsoft.com/en-us/library/… – Daniel Symonds-Lloyd Apr 16 '12 at 9:58
  • I am new to sharepoint and am abit of a n00b at this, do you have an code example or something I could follow as I am struggling to get my head round this. – Alex Nagy Apr 16 '12 at 10:11

Just a typo(!?)

When I pasted your code, I got error: The ComputeExpireDate is not implemented. In your code it is called ComputeExpiteDate ("expite" !)

screencap http://grab.by/d7qe

Another thing: you can't access the HttpContext from a timer job as Daniel Butler said. Send email without HttpContext.

  • I now attempt to compile the code and get the following error, is there a library that I need to call in? Error 1 The type or namespace name 'HttpContext' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Alex.Nagy\Documents\Visual Studio 2010\Projects\ExpirationTest\ExpirationTest\FilteredExpiration.cs 52 17 ExpirationTest Error 2 The name 'HttpContext' does not exist in the current context C:\Users\Alex.Nagy\Documents\Visual Studio 2010\Projects\ExpirationTest\ExpirationTest\FilteredExpiration.cs 52 42 ExpirationTest – Alex Nagy Apr 16 '12 at 9:23
  • 1
    Try to get the custom expiration policy to work. E.g. just change titles on expired items or so. Then you can solve mail sending problems. – Anatoly Mironov Apr 16 '12 at 9:32
  • You can not assume an HttpContext for sending email. This formula can be called from either a SharePoint web request and as part of timer jobs, where there is no HttpContext. – Daniel Symonds-Lloyd Apr 16 '12 at 9:45
  • apologies, I do not understand, which parts do I need to change, thanks again. – Alex Nagy Apr 16 '12 at 9:46
  • exactly, timer job runs outside HttpContext, so you can't use it. Try to send an email without using HttpContext – Anatoly Mironov Apr 16 '12 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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