SharePoint 2013: Custom Expiration Action for SharePoint Retention Policy

SharePoint 2013: Custom Expiration Action for SharePoint Retention Policy



Step 1


Create feature receiver

Step 2


Create xmlManifest

string xmlManifestAction = "<PolicyResource xmlns='urn:schemas-microsoft-com:office:server:policy' " +
                               "id='CustomExpiration.CustomExpirationAction' " +
                               "featureId='Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration' " +
                               "type='Action'>" +
                                   "<Name>CustomExpirationAction</Name>" +
                                   "<Description>This is custom action</Description>" +
                                   "<AssemblyName>CustomExpirationAction, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1c3de238c45ce5cc</AssemblyName>" +
                                   "<ClassName>CustomExpirationAction.CustomExpirationAction</ClassName>" +
                           "</PolicyResource>";


Step 3


Add xmlManifest to PolicyResourceCollection
PolicyResourceCollection.Add(xmlManifestAction);


Step 4


Create CustomExpirationAction class extending IExpirationAction

class CustomExpirationAction : IExpirationAction


Step 5


Create OnExpirationMethod for custom Action

class CustomExpirationAction : IExpirationAction
    {
        public void OnExpiration(SPListItem item, XmlNode parametersData, DateTime expiredDate)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPWeb currentWeb = item.Web)
                {
                    SPList announcementsList = currentWeb.Lists["Announcements"];
                    SPListItem newAnnouncement = announcementsList.Items.Add();
                    newAnnouncement["Title"] = item.Title.ToString() + " has expired";
                    newAnnouncement["Body"] = "Item : " + item.Title.ToString();
                    newAnnouncement.Update();
                }
            });
        }
    }

Leave a Comment
  • Please add 4 and 3 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Richard Mueller edited Revision 3. Comment: Added tags, removed extra space in tag "SharePoint  2010"

  • Gokan Ozcifci edited Revision 2. Comment: formatting

Page 1 of 1 (2 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Gokan Ozcifci edited Revision 2. Comment: formatting

  • Richard Mueller edited Revision 3. Comment: Added tags, removed extra space in tag "SharePoint  2010"

Page 1 of 1 (2 items)