SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When the user publishes a page, I need to automatically schedule it with a start date being as soon as possible, and the end date being a year from the start date. I've tried the event receiver approach (i.e. creating a ScheduledItem and setting the dates accordingly then ListItem.Update() and ScheduledItem.Schedule()) but I get an errro to do with workflow's that I just can't seem to get around.

Does anybody know any other way I can achieve this?

share|improve this question
up vote 2 down vote accepted

Does it look like this:

        using (SPSite site = new SPSite("http://serverName:1111/"))
            using (SPWeb web = site.RootWeb)
                SPList list=web.Lists["Doc Library"];
                SPListItem listItem = list.GetItemById(1);              
                ScheduledItem scheduledItem = null;
                if (ScheduledItem.IsScheduledItem(listItem))
                    scheduledItem = ScheduledItem.GetScheduledItem(listItem);
                    throw new System.ArgumentException
                      ("SPListItem must support scheduling",

                DateTime startDate = new DateTime(2011, 4, 6, 22, 50, 00);
                DateTime endDate = new DateTime(2011, 4, 6, 22, 51, 00);
                scheduledItem.StartDate = startDate;
                scheduledItem.EndDate = endDate;

Source from my bookmarks:

Perhaps if the link doesn't help can you provide more information, perhaps your code isn't quite right on the event receiver. Can you also post the error because afaik you are heading down the right path.

share|improve this answer
It does indeed, it looks exactly like that. What event would you advise this code be included in? I've tried "CheckingIn" and I get an error with a correlation ID (doesn't even get as far as scheduling it), and on "Updating" it appears to have all worked but when I check the page Status I see the error (next to Page Approval failed): "The workflow could not update the item, possibly because one or more columns for the items require a different type of information." Thanks a lot Hugh. – JᴀʏMᴇᴇ Aug 28 '12 at 13:39
I am thinking ItemCheckedIn would be the best place also check properties.ListItem.File.Level == SPFileLevel.Published – Hugh Wood Aug 28 '12 at 13:48
Thanks a lot Hugh, I'll give moving it to CheckedIn a go and report back, appreciate your reply mate thanks. – JᴀʏMᴇᴇ Aug 28 '12 at 13:54
It never satisfies "properties.ListItem.File.Level == SPFileLevel.Published" on CheckedIn I'm afraid Hugh. Not sure where to go from here!? – JᴀʏMᴇᴇ Aug 28 '12 at 15:15
This is turning into a discussion, so all I will say is for the timer job you want to query GetPublishingPages for the pages with the correct status and enddate. If this is beyond then maybe someone else can shed some light on this strange behavior. – Hugh Wood Aug 28 '12 at 16:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.