Programmatically Enable Item Scheduling in SharePoint 2010

Go to Shared Documents=> Library Settings => General Settings => Manage Item Scheduling.


EnableItemScheduling.png


Programmatically enable scheduling of items in the list:

using
System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Microsoft.SharePoint;

using Microsoft.Office.DocumentManagement.MetadataNavigation;

using System.Reflection;

 

namespace EnableItemScheduling

{

    class Program

    {

        static void Main(string[] args)

        {

            using (SPSite site = new SPSite("http://serverName:1111/"))

            {

                using (SPWeb web = site.RootWeb)

                {

                    SPList list = web.Lists.TryGetList("Shared Documents");

                    list.EnableModeration = true;

                    list.EnableMinorVersions = true;

                    list.Update();

                    typeof(Microsoft.SharePoint.Publishing.ScheduledItem).GetMethod("RegisterSchedulingEventOnList", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[] { list });

                }

            }

        }

    }

}