top of page

Programmatically schedule an item in SharePoint 2010

In this article we will be seeing how to schedule an item in SharePoint 2010. An item can be scheduled so that item is visible on the site only between the scheduled start date and end date. An item will be scheduled to be automatically approved (Status-Approved) and to be unpublished (Status-Draft) on specified dates.

Before scheduling the item go to the Library Settings => Add from existing site columns => add the following columns.


Item Scheduling:

  1. using System;

  2. using System.Collections.Generic;

  3. using System.Linq;

  4. using System.Text;

  5. using Microsoft.SharePoint;

  6. using Microsoft.SharePoint.Publishing;

  7. namespace ItemScheduling

  8. {

  9. class Program   

  10. {

  11. static void Main(string[] args)       

  12. {

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

  14. {

  15. using (SPWeb web = site.RootWeb)               

  16. {

  17. SPList list=web.Lists["Doc Library"];

  18. SPListItem listItem = list.GetItemById(1);              

  19. ScheduledItem scheduledItem = null;

  20. if (ScheduledItem.IsScheduledItem(listItem))                   

  21. {                       

  22. scheduledItem = ScheduledItem.GetScheduledItem(listItem);                   

  23. }

  24. else                   

  25. {

  26. throw new System.ArgumentException ("SPListItem must support scheduling", "listItem");                   

  27. }

  28. DateTime startDate = new DateTime(2011, 4, 6, 22, 50, 00);

  29. DateTime endDate = new DateTime(2011, 4, 6, 22, 51, 00);                   

  30. scheduledItem.StartDate = startDate;                   

  31. scheduledItem.EndDate = endDate;                   

  32. scheduledItem.ListItem.Update();                   

  33. scheduledItem.Schedule();               

  34. }           

  35. }       

  36. }   

  37. }

  38. }

Once the item is scheduled you could see the approval Status as "Scheduled".


If the start date is earlier than the current date, the item is published immediately and Approval Status will become "Approved". If not, it is scheduled to publish at a future date.


If the end date is specified, the item is scheduled to unpublished and the Approval Status will become "Draft "at a future date.


0 comments
bottom of page