SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 = "";
            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?

share|improve this question
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.… – 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" !)


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

share|improve this answer
thanks! silly me :) – Alex Nagy Apr 16 '12 at 9:22
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 Expirati‌​onTest 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 Expirati‌​onTest – Alex Nagy Apr 16 '12 at 9:23
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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