Click or drag to resize

Checking Out And Checking In Documents

When the APIDemo application is run with “/m:check” parameters, the following operations are performed:

The snapshot containing search results is created in the same way as in case of downloading a document. See Searching Documents for more information.

The Check Out operation is an example of an operation that can be performed on multiple documents at once. To perform a batch operation, a selection must first be created. A selection is simply a subset of one or more search snapshots (for example search results, linked documents and document tray).

C#
 1Selection selection = new Selection();
 2
 3SnapshotSelection snapshotSelection = new SnapshotSelection();
 4snapshotSelection.SnapshotId = snapshotId;
 5snapshotSelection.DocumentIdList = new int[] { columnsWithValues.DocumentValues[ 0 ].DocumentId };
 6snapshotSelection.MetadataVersionIdList = new int[] { columnsWithValues.DocumentValues[ 0 ].MetadataVersionId };
 7
 8selection.SnapshotSelection = new SnapshotSelection[ 1 ] { snapshotSelection };
 9
10Guid selectionId = documentManager.CreateSelection( selection );

Once the selection is created, a batch operation can be invoked. For example, the following method from Document Manager can be used to check out the documents:

C#
1documentManager.CheckOut( selectionId, false );

Note that the selection is automatically destroyed after a successful batch operation so it doesn't need to be destroyed manually.

After checking out the documents, they must be downloaded just like in case of a regular Get Copy operation. See Searching Documents for more information about downloading documents.

In order to check in a new version of the document, it must be first uploaded to the Document Repository. This is similar to adding a new document:

C#
 1Guid token = repositoryController.CreateUploadToken( fileSize );
 2
 3byte[] buffer = new byte[ 64 * 1024 ];
 4
 5while ( true )
 6{
 7    int read = stream.Read( buffer, 0, buffer.Length );
 8    if ( read == 0 )
 9        break;
10
11    byte[] sendBuffer;
12    if ( read == buffer.Length )
13        sendBuffer = buffer;
14    else
15    {
16        sendBuffer = new byte[ read ];
17        Array.Copy( buffer, sendBuffer, read );
18    }
19
20    repositoryController.UploadFileDataChunk( token, sendBuffer );
21}

Unlike the Check Out operation, Check In can only be performed on a single document at a time. Because of that, the metadata version ID of the document must be passed, instead of a selection ID. In addition, the upload token from the repository must also be passed. This associates the new version of the document with the file in the repository.

C#
1documentManager.CheckIn( token, DocumentManagerService.CheckInOptions.CreateNewVersion, filename,
2  Path.GetFileNameWithoutExtension( filename ), metadataVersionId, false );

After checking in, the new version of the document has the same metadata values as the previous version, but the document name and file extension can be changed during the check in operation. The metadata version ID of the new document version is returned by the CheckIn method and can be passed to SetMetadata method in order to modify the metadata values.