Click or drag to resize

Adding And Editing Documents

The following operations are performed when the APIDemo application is started with “/m:put” parameters:

To create document schemas and metadata fields, the Document Schema Manager service can be used. It also provides methods for retrieving, modifying and deleting existing schemas and fields. In order to manage schemas and fields, at least Library Administration permissions are required.

Similarly the Library Structure Manager can be used to create and manipulate cabinets, drawers, folder groups (also known as categories) and folders and to retrieve the library structure. For performance reasons, cabinets are always retrieved with drawers and individual drawers can be populated with folder groups and folders.

The first step to add a new document to the library, unless an offline document is added, is to create a new upload token and upload the file to the document repository. The process is similar to downloading and for larger files can be performed in chunks.

 1Guid token = repositoryController.CreateUploadToken( fileSize );
 3byte[] buffer = new byte[ 64 * 1024 ];
 5while ( true )
 7    int read = stream.Read( buffer, 0, buffer.Length );
 8    if ( read == 0 )
 9        break;
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    }
20    repositoryController.UploadFileDataChunk( token, sendBuffer );

Once the document is uploaded, the metadata values must be specified according to the selected schema. Depending on the field type, values should be specified as:

Note that the types are slightly different than the ones returned from Document Finder, where dropdown and drilldown fields are represented as DropdownFieldChoice[] and DrilldownFieldChoice[] respectively.

1FieldWithValue text = new FieldWithValue();
2text.FieldId = textFieldId;
3text.Value = "hello, world";
5FieldWithValue number = new FieldWithValue();
6number.FieldId = numberFieldId;
7number.Value = 1.23m;
9FieldWithValue[] fields = new FieldWithValue[ 2 ] { text, number };

The document can be added using the Document Manager service. The upload token of the file is also passed and the uploaded file is automatically committed in the repository and queued for full text search indexing.

1DocumentInfo info = new DocumentInfo();
2info.FolderId = folderId;
3info.DocumentSchemaId = documentSchemaId;
4info.DocumentName = Path.GetFileNameWithoutExtension( filePath );
5info.FieldsWithValues = fields;
6info.UploadToken = token;
7info.OriginalFileName = Path.GetFileName( filePath );
8int metadataVersionId = documentManager.AddDocumentInfo( info );

In order to modify the metadata of an existing document, the SetMetadata method of Document Manager service can be used. Pass the new document name, document schema ID and metadata field values in the same format, as when adding a document:

1documentManager.SetMetadata( metadataVersionId, documentSchemaId, Path.GetFileNameWithoutExtension( filePath ),
2  fields, false, null );