Export (0) Print
Expand All

SPFile.ScheduleEnd method

Sets the date on which a file will be removed from public views of a document library.

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

public void ScheduleEnd(
	DateTime endDate
)

Parameters

endDate
Type: System.DateTime

A DateTime value that specifies when the file should be unpublished (removed from public views).

ExceptionCondition
UnauthorizedAccessException

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

SPException

The value of the document library EnableModeration property is false.

SPException

The value of the document library EnableMinorVersions property is false.

This method schedules the date and time when the file is removed from public views.

To ensure that the content never expires, pass MaxValue as the value of the endDate parameter.

This example sets the expiration date for a file to a specified number of days from the present date.

public void Retire(SPFile file, double days)
{
    // Set an expiration date only after content has been published.
    if ((file != null) && (file.Level == SPFileLevel.Published))
    {
        try
        {
            file.ScheduleEnd(DateTime.Now.AddDays(days));
        }
        catch (SPException ex)
        {
            // error handling
        }
    }
    else
    {
        throw new Exception("A file must be published before you can schedule it for retirement.");
    }
}
Show:
© 2014 Microsoft