Share via


ScheduledItem.Schedule Method (String)

Schedules an SPListItem object to automatically be approved (start) and be unpublished (end) on specified dates.

Namespace:  Microsoft.SharePoint.Publishing
Assembly:  Microsoft.SharePoint.Publishing (in Microsoft.SharePoint.Publishing.dll)

Syntax

'Declaration
Public Sub Schedule ( _
    approvalComment As String _
)
'Usage
Dim instance As ScheduledItem
Dim approvalComment As String

instance.Schedule(approvalComment)
public void Schedule(
    string approvalComment
)

Parameters

  • approvalComment
    Type: System.String

    Comments to be set when the SPListItem is approved if the StartDate is in the future.

Exceptions

Exception Condition
[Microsoft.SharePoint.SPException]

You can schedule documents only in a minor version-enabled list.

[Microsoft.SharePoint.SPException]

You can schedule documents only in a list with content approval enabled.

[Microsoft.SharePoint.SPException]

The current user does not have sufficient permissions to perform this action.

[Microsoft.SharePoint.SPException]

Scheduling a start date for a currently approved item is not supported. Items must be in the minor version state.

[Microsoft.SharePoint.SPException]

Scheduling is not supported in this content database. Use Approve or Unpublish instead.

Remarks

Scheduling an SPListItem indicates that it has already been effectively approved. The same permissions required for scheduling are required for approval.

The StartDate and EndDate values are used to determine the publication schedule. If the start date is earlier than now, the SPListItem is published immediately. Otherwise, it is scheduled to publish at a future date. If the end date is specified, the SPListItem is scheduled to unpublish at a future date.

Examples

This sample sets a start and end date for a ScheduledItem object and schedules the item so that it is published when the start date is reached and it is unpublished when the end date is reached.

Before compiling and running this sample, verify that the SPListItem is a list item in a document library that supports scheduling.

using ScheduledItem = Microsoft.SharePoint.Publishing.ScheduledItem;
using SPModerationStatusType = Microsoft.SharePoint.SPModerationStatusType;
using SPListItem = Microsoft.SharePoint.SPListItem;
using DateTime = System.DateTime;

namespace Microsoft.SDK.SharePointServer.Samples
{
    public static class ScheduledItemCodeSamples
    {
        public static void SetDatesAndSchedule(SPListItem listItem, 
          DateTime startDate, DateTime endDate)
        {
            // Set the input parameter values with
            // your own values.
            
            //
            // validate the input parameters
            if (null == listItem)
            {
                throw new System.ArgumentNullException("listItem");
            }

            // Get the ScheduledItem wrapper for the SPListItem
            // that was passed in.
            //
            ScheduledItem scheduledItem = null;
            if (ScheduledItem.IsScheduledItem(listItem))
            {
                scheduledItem = ScheduledItem.GetScheduledItem(listItem);
            }
            else
            {
                throw new System.ArgumentException
                  ("The document library containing this SPListItem must support scheduling", 
                  "listItem");
            }

            // Set and save the date values.
            scheduledItem.StartDate = startDate;
            scheduledItem.EndDate = endDate;
            scheduledItem.ListItem.Update();

            // Schedule the item so that the StartDate and EndDate
            // take effect.
            scheduledItem.Schedule();
        }        
    }
}
Imports ScheduledItem = Microsoft.SharePoint.Publishing.ScheduledItem
Imports SPModerationStatusType = Microsoft.SharePoint.SPModerationStatusType
Imports SPListItem = Microsoft.SharePoint.SPListItem

Namespace Microsoft.SDK.SharePointServer.Samples
    Public NotInheritable Class ScheduledItemCodeSamples
        Private Sub New()
        End Sub
        Public Shared Sub SetDatesAndSchedule(ByVal listItem As SPListItem, ByVal startDate As Date, ByVal endDate As Date)
            ' Set the input parameter values with
            ' your own values.

            '
            ' validate the input parameters
            If Nothing Is listItem Then
                Throw New System.ArgumentNullException("listItem")
            End If

            ' Get the ScheduledItem wrapper for the SPListItem
            ' that was passed in.
            '
            Dim scheduledItem As ScheduledItem = Nothing
            If ScheduledItem.IsScheduledItem(listItem) Then
                scheduledItem = ScheduledItem.GetScheduledItem(listItem)
            Else
                Throw New System.ArgumentException ("The document library containing this SPListItem must support scheduling", "listItem")
            End If

            ' Set and save the date values.
            scheduledItem.StartDate = startDate
            scheduledItem.EndDate = endDate
            scheduledItem.ListItem.Update()

            ' Schedule the item so that the StartDate and EndDate
            ' take effect.
            scheduledItem.Schedule()
        End Sub
    End Class
End Namespace

See Also

Reference

ScheduledItem Class

ScheduledItem Members

Schedule Overload

Microsoft.SharePoint.Publishing Namespace

StartDate

EndDate

Approve

Schedule