Condividi tramite


SPFile.CheckOut Method

Checks the file out 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
<ClientCallableExceptionConstraintAttribute(FixedId := "2", ErrorType := GetType(UnauthorizedAccessException),  _
    Condition := "Insufficient permissions to perform operation")> _
<ClientCallableAttribute> _
<ClientCallableExceptionConstraintAttribute(FixedId := "1", ErrorType := GetType(SPFileCheckOutException),  _
    ErrorCode := , Condition := "The file is already checked out for editing.")> _
Public Sub CheckOut
'Usage
Dim instance As SPFile

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

Exceptions

Exception Condition
SPException

An error occurred when checking out the file.

Remarks

This method calls CheckOut(SPFile.SPCheckOutType, String) with Online and null .

Examples

The following code example shows how to check out all the files in the Shared Documents folder for a specified subsite.

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

For i = 0 To docLibFiles.Count - 1

    docLibFiles(i).CheckOut()

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++)
{
    collFiles[intIndex].CheckOut();
}
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

CheckOut Overload

Microsoft.SharePoint Namespace