Condividi tramite


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

Syntax

'Declaration
Public Sub CheckIn ( _
    comment As String _
)
'Usage
Dim instance As SPFile
Dim comment As String

instance.CheckIn(comment)
public void CheckIn(
    string comment
)

Parameters

  • comment
    Type: System.String

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

Exceptions

Exception Condition
SPException

An error occurred when checking in the file.

Remarks

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.

Examples

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

        docLibFiles(i).CheckIn("Checkin_Comment")

    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")
        {
            oFolder[intIndex].CheckIn("Checkin_Comment");
        }
    }
}

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

CheckIn Overload

Microsoft.SharePoint Namespace