SPFile.CheckOut Method () (Microsoft.SharePoint)
Checks the file out of a document library.

Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Syntax

Visual Basic (Declaration)
Public Sub CheckOut
Visual Basic (Usage)
Dim instance As SPFile

instance.CheckOut
C#
public void CheckOut ()
Example

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

Visual Basic
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
C#
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();
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 Best Practices: Using Disposable Windows SharePoint Services Objects.

See Also

Tags :


Page view tracker