SharePoint API does not allow to programmatically modify scheduling on a List.
So here is the code that does this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Microsoft.SharePoint;
namespace YourNameSpace{
/// <summary>
/// Class for operation that enables operations that are not enabled via standard SharePoint API
/// </summary>
public static class PublishingUtilities
{
const string SharePointPublishingAssemblyName = "Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c";
const string ScheduledItemClassName = "Microsoft.SharePoint.Publishing.ScheduledItem";
/// <summary>
/// Registers Scheduling on a List
/// </summary>
/// <param></param>
public static void EnableSchedulingEventOnList(this SPList list)
{
Assembly assembly = Assembly.Load(SharePointPublishingAssemblyName);
Type type = assembly.GetType(ScheduledItemClassName);
MethodInfo dynMethod = type.GetMethod("RegisterSchedulingEventOnList", BindingFlags.NonPublic | BindingFlags.Static);
dynMethod.Invoke(type, new object[] { list });
}
/// <summary>
/// Unregisters Scheduling on a List
/// </summary>
/// <param></param>
public static void DisableSchedulingOnList(this SPList list)
{
Assembly assembly = Assembly.Load(SharePointPublishingAssemblyName);
Type type = assembly.GetType(ScheduledItemClassName);
MethodInfo dynMethod = type.GetMethod("DisableSchedulingOnList", BindingFlags.NonPublic | BindingFlags.Static);
dynMethod.Invoke(type, new object[] { list });
}
/// <summary>
/// Gets scheduling state on the List
/// </summary>
/// <param></param>
public static bool GetIsSchedulingEventRegisteredOnList(this SPList list)
{
Assembly assembly = Assembly.Load(SharePointPublishingAssemblyName);
Type type = assembly.GetType(ScheduledItemClassName);
MethodInfo dynMethod = type.GetMethod("GetIsSchedulingEventRegisteredOnList", BindingFlags.NonPublic | BindingFlags.Static);
bool? result = dynMethod.Invoke(type, new object[] { list }) as bool?;
if (result != null)
return result.Value;
else
throw new ArgumentException("Call of the function GetIsSchedulingEventRegisteredOnList failed");
}
}
}