Check out to file system
This example shows how you can check out a document to file system. The check out operation downloads the first section of the document while also marking it as checked out. The downloaded file downloaded file has the document address encoded in the file name. The check in operation takes a file with name that has document address encoded which is the replacement of the first section of the document. After the successful upload the document checkout mark is deleted.
Check in/out file name format
- The file name starts with the document id encoded as decimal number.
- The next character is a plus sign (+).
- The next part is the id of the file cabinet. It is formatted as string which contains only characters a-f and digits and dashes ('-'). More precisely, it is a GUID using the following pattern: 00000000-0000-0000-0000-000000000000.
- The next character is a plus sign (+).
- Optionally the document name can follow. The document name must consist only of the following characters. Any character not matching these rules is not allowed and must be replaced with an underscore ().
- Each character of the Unicode class letter is allowed.
- Any digit (0-9) is allowed.
- The white space character with the code 32 is allowed. Also the underscore () is allowed.
- The file name ends with the file extension, beginning with a period.
- The file name length, including the extension, does not exceed 80 characters.
Check out file to file system and check it back in.
Check out file to file system and check it back in.
C#
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using DocuWare.Platform.ServerClient;
using DocuWare.Services.Http;
namespace DocuWare.PlatformClientExamples
{
static partial class ExamplesAsync
{
public static async Task<Document> CheckOutCheckInAsync(ServiceConnection connection, string fileCabinetId, int docId)
{
var fileInfo = await CheckOutToFileSystem(connection, fileCabinetId, docId).ConfigureAwait(false);
// Do something with the file, e.g. open it in external editor and wait until the editing operation is finished.
await Task.Delay(2000).ConfigureAwait(false);
var checkInData = new CheckInActionParameters() { Comments = "comments...", DocumentVersion = new DocumentVersion() { Major = 1, Minor = 1 } };
return await connection.EasyCheckInFromFileSystemAsync(fileInfo, checkInData).ConfigureAwait(false);
}
public static async Task<FileInfo> CheckOutToFileSystem(ServiceConnection connection, string fileCabinetId, int docId)
{
using (var result = await connection.EasyCheckOutToFileSystemAsync(fileCabinetId, docId).ConfigureAwait(false))
{
var tempPath = Path.Combine(Path.GetTempPath(), result.EncodedFileName);
using (var file = System.IO.File.Create(tempPath))
using (var stream = result.Response.Content)
await stream.CopyToAsync(file).ConfigureAwait(false);
return new FileInfo(tempPath);
}
}
}
}