共用方式為


SPFile.UndoCheckOut Method

Undoes the file checkout.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
<ClientCallableAttribute> _
<ClientCallableExceptionConstraintAttribute(FixedId := "1", ErrorType := GetType(SPFileCheckOutException),  _
    ErrorCode := , Condition := "The file is not checked out.")> _
<ClientCallableExceptionConstraintAttribute(FixedId := "2", ErrorType := GetType(UnauthorizedAccessException),  _
    Condition := "Insufficient permissions to perform operation")> _
Public Sub UndoCheckOut
'Usage
Dim instance As SPFile

instance.UndoCheckOut()
[ClientCallableAttribute]
[ClientCallableExceptionConstraintAttribute(FixedId = "1", ErrorType = typeof(SPFileCheckOutException), 
    ErrorCode = , Condition = "The file is not checked out.")]
[ClientCallableExceptionConstraintAttribute(FixedId = "2", ErrorType = typeof(UnauthorizedAccessException), 
    Condition = "Insufficient permissions to perform operation")]
public void UndoCheckOut()

Exceptions

Exception Condition
SPException

An error occurred while undoing the file checkout.

Remarks

This method reverts an existing online or offline checkout for the current file.

Examples

The following code example undoes the checkout for files in the Shared Documents document library of a subsite if the specified user is the one who checked them out.

Dim siteCollection As SPSite = SPContext.Current.Site
Dim site As SPWeb = siteCollection.AllWebs("Site_Name/Subsite_Name")
Dim docLibFolder As SPFolder = site.Folders("Shared Documents")
Dim docLibFiles As SPFileCollection = docLibFolder.Files
Dim i As Integer

For i = 0 To docLibFiles.Count - 1

    If docLibFiles(i).CheckedOutBy.LoginName = "Domain_Name\User" Then

        docLibFiles(i).UndoCheckOut()

    End If

Next i
SPSite oSiteCollection = SPContext.Current.Site;
SPWeb oWebsite = oSiteCollection.AllWebs["Site_Name/Subsite_Name"]
SPFolder oFolder = oWebsite.Folders["Shared Documents"];
SPFileCollection collFiles = oFolder.Files;

for (int intIndex=0; intIndex<collFiles.Count; intIndex++)
{
    if (collFiles[intIndex].CheckedOutBy.LoginName == "Domain_Name\\User")
    {
        collFiles[intIndex].UndoCheckOut();
    }
}
oWebsite.Dispose();

Note

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

See Also

Reference

SPFile Class

SPFile Members

Microsoft.SharePoint Namespace