IVersionableItem.CheckIn Method 

IT Hit WebDAV for .NET

Creates new version. Copies all properties and content from this item.

[Visual Basic]
Function CheckIn( _
   ByRef newVersionUrl As String _
) As WebDAVResponse
[C#]
WebDAVResponse CheckIn(
   out string newVersionUrl
);

Parameters

newVersionUrl
Url of the newly created version.

Return Value

Remarks

In your implementation you must create a new version. The content and properties of the new version must be copied from this item.

After the call to this method property CurrentVersion must point to the created version.

Example

public WebDAVResponse CheckIn(out string newVersionUrl)
{
    // Create new version. Copy content and properties from this item to new version.
    using (SqlConnection conn = new SqlConnection(fConnStr))
    {
        conn.Open();
        SqlCommand cmd = conn.CreateCommand();

        Version version = this.VersionHistory.CurrentVersion as Version;
        int newVersionNumber = version.VersionNumber + 1;
        string newVersionPath = Version.CreateVersionPath(this.fPath, newVersionNumber);

        SetResourceCheckedOut(false);

        // Create new version.
        cmd.CommandText =
            "SET @Identity = NEWID()"
            + " INSERT INTO Version"
            + " (ItemId, VersionId, VersionNumber, Name, Comment,"
            + " CreatorDisplayName, ContentType, Created)"
            + " SELECT @ItemId, @Identity, @VersionNumber, Name, Comment,"
            + " @CreatorDisplayName, ContentType, GETUTCDATE()"
            + " FROM Item"
            + " WHERE ItemId = @ItemId";
        cmd.Parameters.Add("@ItemId", SqlDbType.UniqueIdentifier).Value = this.fItemId;
        cmd.Parameters.Add("@VersionNumber", SqlDbType.Int).Value = newVersionNumber;
        cmd.Parameters.Add("@CreatorDisplayName", SqlDbType.NVarChar).Value = CurrentUserName;
        SqlParameter idParm = cmd.Parameters.Add("@Identity", SqlDbType.UniqueIdentifier);
        idParm.Direction = ParameterDirection.Output;
        cmd.ExecuteNonQuery();

        cmd.Parameters.Clear();
        cmd.CommandText = "UPDATE Item SET Comment = '' WHERE ItemId = @ItemId";
        cmd.Parameters.Add("@ItemId", SqlDbType.UniqueIdentifier).Value = this.fItemId;

        cmd.ExecuteNonQuery();

        Guid newID = (Guid)idParm.Value;

        // Copy properties to new version
        cmd.CommandText =
            "INSERT INTO VersionProperty"
            + " (VersionId, Name, Namespace, PropVal)"
            + " SELECT @VersionId, Name, Namespace, PropVal"
            + " FROM Property"
            + " WHERE ItemID = @ItemID";

        cmd.Parameters.Add("@VersionId", SqlDbType.UniqueIdentifier).Value = newID;
        cmd.ExecuteNonQuery();

        // Copy content to new version
        File.Copy(this.fFilePath, this.fItemDir + "\\" + newVersionNumber);
        newVersionUrl = newVersionPath;
    }
    return new OkResponse();
}
 

See Also

IVersionableItem Interface | ITHit.WebDAV.Server.DeltaV Namespace