SPFile.ScheduleStart method (DateTime, Boolean, String)

Schedules the automatic approval of a document in a moderated library at the specified date and time, with the specified approval comment, and optionally changes the moderation status of the list item.

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

Syntax

'Declaration
Public Sub ScheduleStart ( _
    startDate As DateTime, _
    setModerationStatus As Boolean, _
    approvalComment As String _
)
'Usage
Dim instance As SPFile
Dim startDate As DateTime
Dim setModerationStatus As Boolean
Dim approvalComment As String

instance.ScheduleStart(startDate, setModerationStatus, _
    approvalComment)
public void ScheduleStart(
    DateTime startDate,
    bool setModerationStatus,
    string approvalComment
)

Parameters

  • startDate
    Type: System.DateTime

    The date and time when the document is approved.

  • approvalComment
    Type: System.String

    The explanation why the item was approved. This method stores this value in the SPListItem.ModerationInformation.Comment property.

Exceptions

Exception Condition
UnauthorizedAccessException

The current user does not have the SPBasePermissions.ApproveItems permissions.

SPException

The value of the document library EnableModeration property is false.

SPException

The value of the document library EnableMinorVersions property is false.

SPException

The document is already approved (The value of the ModerationInformation property of the list item is SPModerationStatusType.Approved).

-or-

Minor versioning is not enabled for the document library.

Remarks

This method creates a work-item timer job that calls the Approve(String) method at a specific date and time. If another job of the same type has already been created for the file, it is replaced by this new job. When the specified date and time arrive, the file is approved and published. It then becomes visible in public views of the document library.

Scheduling status is tracked through the ModerationInformation property of the list item. If true is passed as an argument to the setModerationStatus parameter of the ScheduleStart method, the ModerationInformation property is set to SPModerationStatusType.Scheduled. If you do not want to show approval as scheduled, pass false as the argument.

Because the ScheduleStart method essentially approves the file in advance of its publication, the current user must have the SPBasePermissions.ApproveItems permission. When the timer job created by this method eventually executes, the value of the ModerationInformation property of the list item is set to SPModerationStatusType.Approved, and the text string passed as the argument to the approvalComment parameter is set as the value of the list item’s SPListItem.ModerationInformation.Comment property.

Content approval results in the elevation of a minor version of the file to a major version. Only minor versions may be scheduled, and only major versions are published. For this process to work, minor versioning must be enabled for the document library.

Examples

This example schedules an approval work item for a file in a document library. The approval is scheduled to take place in the early morning hours on the day after the request.

public void Approve(SPListItem item, string comment)
{
    SPFile file = item.File;

    // Be sure we have a file to work with.
    if (file != null)
    {
        // Check in any file that is checked out.
        if (file.Level == SPFileLevel.Checkout)
        {
            file.CheckIn(String.Empty, SPCheckinType.MinorCheckIn);
        }

        // Queue it up at 2 am tomorrow.
        DateTime startDate = DateTime.Now.Date.AddHours(2.0);
        try
        {
            file.ScheduleStart(startDate, true, comment);
        }
        catch (SPException ex)
        {
            // Handle Sharepoint errors
        }
    }
}  
Public Sub Approve(ByRef item As SPListItem, ByVal comment As String)

    Dim file As SPFile = item.File

    ' Be sure we have a file to work with.
    If (file Is Nothing) Then

        ' Check in any file that is checked out.
        If file.Level = SPFileLevel.Checkout Then

            file.CheckIn(String.Empty, SPCheckinType.MinorCheckIn)

        End If

        'Queue it up at 2 am tomorrow.
        DateTime(startDate = DateTime.Now.Date.AddHours(2.0))
        Try

            file.ScheduleStart(startDate, True, comment)

        Catch ex As SPException

            ' Handle Sharepoint errors

        End Try

    End If

End Sub

See also

Reference

SPFile class

SPFile members

ScheduleStart overload

Microsoft.SharePoint namespace

Approve

ScheduleEnd

ModerationInformation

SPModerationStatusType