Share via


ScheduledItem.EndDate Property

Gets or sets the Coordinated Universal Time (UTC) at which this ScheduledItem class ends and is no longer visible on the published site.

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

Syntax

'Declaration
Public Property EndDate As DateTime
    Get
    Set
'Usage
Dim instance As ScheduledItem
Dim value As DateTime

value = instance.EndDate

instance.EndDate = value
public DateTime EndDate { get; set; }

Property Value

Type: System.DateTime
The Coordinated Universal Time (UTC) at which this ScheduledItem class ends and is no longer visible on the published site.

Exceptions

Exception Condition
[System.ArgumentNullException]

This value cannot be set to a null reference (Nothing in Visual Basic).

[System.UnauthorizedAccessException]

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

Remarks

A value of January 01, 2050, indicates that an instance of the ScheduledItem class is no longer visible on the published site. If the end date is set to this value, the property is displayed by using the string "Never" in the corresponding user interfaces.

To save changes after setting this property, call the ScheduledItem.ListItem.Update() method.

The date and time returned by this property can be converted from UTC to local time in server-side code by using SPRegionalSettings.TimeZone.UTCToLocalTime(DateTime) method.

The user must have edit permissions on the PublishingPage to set this value. The user must have view permissions on the PublishingPage to initially retrieve it and get any of its property values.

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();
        }        
    }
}

See Also

Reference

ScheduledItem Class

ScheduledItem Members

Microsoft.SharePoint.Publishing Namespace

[Microsoft.SharePoint.SPTimeZone.UTCToLocalTime(System.DateTime)]

[Microsoft.SharePoint.SPContext.RegionalSettings]