public override void ItemCheckingIn(SPItemEventProperties properties)
{
base.ItemCheckingIn(properties);
#region Automatic Scheduling
ScheduledItem scheduledItem = null;
if (ScheduledItem.IsScheduledItem(properties.ListItem))
{
scheduledItem = ScheduledItem.GetScheduledItem(properties.ListItem);
}
else
{
throw new System.ArgumentException("The document library containing this SPListItem must support scheduling", "listItem");
}
if (scheduledItem.StartDate < new DateTime(1991, 12, 12))
{
scheduledItem.StartDate = DateTime.Now.AddYears(1);
scheduledItem.EndDate = DateTime.Now.AddYears(2);
scheduledItem.ListItem.Update();
scheduledItem.Schedule();
}
#endregion
}
Please ignore the poor if evaluation of the StartDate, it is (for now) one way of me stopping the CheckingIn event from looping (in the future I'll look into how to properly tell if a schedule has already been set).
Basically, when I click 'publish', this event is fired as expected. But the error in the browser is "The URL [URL]is invalid. It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current Web."
The aim of all this is to set an automatic scheduling for pages on Publishing them.