Custom Expiration policy C# help
-
Montag, 16. April 2012 08:07
Hi,
I was wandering if you could help, I am attempting to create the following policy.
I have named the policy FilteredExpiration.cs
When I go to build it, it comes up with 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
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) SendWarningEmail(item); } if (item["CollectMe"].ToString().Equals("True")) return DateTime.Now; else return ((DateTime)item["Modified"]).AddDays(365); } private void SendWarningEmail(SPListItem item) { try { 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 } } } }
any ideas ?
Alle Antworten
-
Montag, 16. April 2012 09:00
Your method signature does not match the interface.
DateTime? its different than Nullable<DateTime>
Change it and let me know if it compiles, also change the typo error.ComputeExpiteDate to ComputeExpireDate
Follow me on Twitter <<<
levalencia Blog <<<- Bearbeitet Luis Esteban Valencia M Montag, 16. April 2012 11:15
- Als Antwort vorgeschlagen Luis Esteban Valencia M Montag, 16. April 2012 11:15
- Als Antwort markiert Qiao WeiMicrosoft Contingent Staff, Moderator Donnerstag, 26. April 2012 09:40
-
Montag, 16. April 2012 09:11
Hi,
Thanks for the reply. I have had a look at the link and have changed it too:
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 Nullable <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) SendWarningEmail(item); } if (item["CollectMe"].ToString().Equals("True")) return DateTime.Now; else return ((DateTime)item["Modified"]).AddDays(365); }I still get the 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
-
Montag, 16. April 2012 10:49Moderator
Hi
There's a typo in your code. The interface method's name is ComputeExpireDate. You have named it ComputeExpiteDate..
Regards Bjoern
-
Montag, 16. April 2012 13:47
My bad.
I have since corrected the spelling mistake in the code and I am now getting the following error.
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
-
Montag, 16. April 2012 13:49
you have to add a reference to System.Web
https://www.google.com/search?ix=sea&sourceid=chrome&ie=UTF-8&q=HttpContext
Follow me on Twitter <<<
levalencia Blog <<< -
Montag, 16. April 2012 14:00
Hi,
I have already put using system.web at the top of the code, do I need to reference it again further down the 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 Nullable <DateTime> ComputeExpireDate(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) SendWarningEmail(item); } if (item["CollectMe"].ToString().Equals("True")) return DateTime.Now; else return ((DateTime)item["Modified"]).AddDays(365); } private void SendWarningEmail(SPListItem item) { try { 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 } } } }
-
Montag, 16. April 2012 14:14
system.web.dll is not added to the project by default, you have to add it before you can use it in the using statement.
References, right click, add reference, find the dll
Follow me on Twitter <<<
levalencia Blog <<<- Als Antwort markiert Qiao WeiMicrosoft Contingent Staff, Moderator Donnerstag, 26. April 2012 09:40
-
Dienstag, 26. Februar 2013 13:49
Just for clarification sake, actually, DateTime? is not different than Nullable<DateTime>. Albeit different from the MSDN example you referenced, the code sample below uses DateTime?
http://code.msdn.microsoft.com/office/SharePoint-2010-Developing-37ad2f01/sourcecode?fileId=49663&pathId=934555589
DateTime? is shorthand for Nullable<DateTime> as with Int?, GUID? etc. etc.
M

