Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.
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.

share|improve this question
    
You might would like to set a breakpoint at start of your method and attach your code to "OWSTimer.exe" process and check where exactly its throwing error. –  Ignacio Aug 29 '12 at 15:50

1 Answer 1

My guess is that it's because you are trying to update the item before it is ready. Your event is ItemCheckingIn instead of ItemCheckedIn. The only place this is pulling an item is your line:

scheduledItem = ScheduledItem.GetScheduledItem(properties.ListItem);

But the error is probably being thrown on:

scheduledItem.ListItem.Update();

I might be wrong (I have been before), but I'd assume this is your issue.

Try to debug it and let us know what you find.

share|improve this answer

Your Answer

 
discard

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.