Download the Content of a Single Document
This example shows how you can download and store the content of a document in a file. Additionaly the access to a document is shown where you have the document id and file cabinet id only.
In order the get the file name, file content type and file size the data structures of the example Download a Document are used.
Download a document to a file
C#
using System;
using System.Collections.Generic;
using System.Linq;
using DocuWare.Platform.ServerClient;
namespace DocuWare.PlatformClientExamples
{
static partial class Examples
{
public static FileDownloadResult DownloadSingleDocumentContent(ServiceConnection connection, int docId, string fileCabinetId)
{
var document = connection.GetFromDocumentForDocumentAsync(docId, fileCabinetId).Result;
var downloadedFile = Examples.DownloadDocumentContent(document);
Console.WriteLine("Copy document {0} with content type {2} to {1}.",
docId, downloadedFile.FileName, downloadedFile.ContentType);
using (var file = System.IO.File.Create(downloadedFile.FileName))
using (var stream = downloadedFile.Stream)
stream.CopyTo(file);
return downloadedFile;
}
}
}
Download a document to a file asynchronously
The header fields can be accessed straight forward in the asynchronous API.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DocuWare.Platform.ServerClient;
namespace DocuWare.PlatformClientExamples
{
static partial class ExamplesAsync
{
public static async Task<FileDownloadResult> DownloadSingleDocumentContentAsync(ServiceConnection connection, int docId, string fileCabinetId)
{
var document = await connection.GetFromDocumentForDocumentAsync(docId, fileCabinetId).ConfigureAwait(false);
var downloadedFile = await DownloadDocumentContentAsync(document).ConfigureAwait(false);
Console.WriteLine("Copy document {0} with content type {2} to {1}.",
docId, downloadedFile.FileName, downloadedFile.ContentType);
using (var file = System.IO.File.Create(downloadedFile.FileName))
using (var stream = downloadedFile.Stream)
await stream.CopyToAsync(file).ConfigureAwait(false);
return downloadedFile;
}
}
}