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

[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()

ExceptionCondition
SPException

An error occurred while undoing the file checkout.

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

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.

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

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.

Show: