SPFile.CheckIn Method (String)

Checks in the file to a document library with the specified comment.

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


Public Sub CheckIn ( _
    comment As String _
Dim instance As SPFile
Dim comment As String

public void CheckIn(
    string comment


  • comment
    Type: System.String

    A string that contains a comment about the check-in.


Exception Condition

An error occurred when checking in the file.


This method calls CheckIn(String, SPCheckinType) with the second argument set to MinorCheckIn.

Although a check-in comment is not required in the UI, the CheckIn method requires a comment, which can be an empty string, as its parameter.

If versioning is enabled for the document library that contains the file, the CheckIn method creates an SPFileVersion object.


The following code example checks files back into the Shared Documents document library of a subsite if the specified user is the one who checked them out.

Dim site As SPSite = SPContext.Current.Site
Dim web As SPWeb = site.AllWebs("Site_Name/Subsite_Name")
Dim docLibFolder As SPFolder = web.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 = "User_Name" Then


    End If

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

    SPFileCollection collFiles = oFolder.Files;

    for (int intIndex=0; intIndex<oFolder.Count; intIndex++)
        if (oFolder[intIndex].CheckedOutBy.LoginName == "User_Name")


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


SPFile Class

SPFile Members

CheckIn Overload

Microsoft.SharePoint Namespace