ScheduledItem.GetScheduledItem Method
Static method to retrieve an instance of the ScheduledItem class that wraps the specified SPListItem class.
Namespace: Microsoft.SharePoint.Publishing
Assembly: Microsoft.SharePoint.Publishing (in Microsoft.SharePoint.Publishing.dll)
Syntax
'Declaration
Public Shared Function GetScheduledItem ( _
sourceListItem As SPListItem _
) As ScheduledItem
'Usage
Dim sourceListItem As SPListItem
Dim returnValue As ScheduledItem
returnValue = ScheduledItem.GetScheduledItem(sourceListItem)
public static ScheduledItem GetScheduledItem(
SPListItem sourceListItem
)
Parameters
- sourceListItem
Type: Microsoft.SharePoint.SPListItem
The SPListItem to wrap in a ScheduledItem instance
Return Value
Type: Microsoft.SharePoint.Publishing.ScheduledItem
A ScheduledItem instance that wraps the specified SPListItem
Exceptions
Exception | Condition |
---|---|
[System.ArgumentException] | Invalid SPListItem. The SPListItem provided is not compatible with a ScheduledItem. This indicates that the SPListItem is either not part of a document library that supports scheduling; or does not have start and end dates, which are required for scheduling. |
[System.ArgumentNullException] | The sourceListItem parameter cannot be a null reference (Nothing in Visual Basic). |
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.
[c#]
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)
{
// TODO: 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();
}
}
}