共用方式為


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)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public Sub ScheduleEnd ( _
    endDate As DateTime _
)
'Usage
Dim instance As SPFile
Dim endDate As DateTime

instance.ScheduleEnd(endDate)
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).

Exceptions

Exception Condition
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.

Remarks

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.

Examples

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.");
    }
}
Public Sub Retire(ByRef file As SPFile, ByVal days As Double)

    'Set an expiration date only after content has been published.
    If (file Is Nothing) And (file.Level = SPFileLevel.Published) Then

        Try

            file.ScheduleEnd(DateTime.Now.AddDays(days))

        Catch ex As SPException

            ' error handling

        End Try

    Else

        Throw New Exception("A file must be published before you can schedule it for retirement.")

    End If

End Sub

See Also

Reference

SPFile Class

SPFile Members

Microsoft.SharePoint Namespace

ScheduleStart

UnPublish

SPFileLevel