Get all Documents of a Basket or File Cabinet
This example shows you how you can access all documents of a basket or a file cabinet. This is basically the same operation, because a basket and a file cabinet are very similar structures.
In order to get all documents of a basket or file cabinet, you can use the GetFromDocumentsForDocumentsQueryResultAsync() extension method. You can provide optional parameters where you can set the number of documents to be returned or which fields you want to have.
In the following example we use the function GetAllDocuments to get recursive all documents. The count parameter is used to set the amount of documents per request. That means if the parameter is set to 100
every request one hundred documents would be when available returned.
Note
You should not try to get all items of a file cabinet in a production environment. Rather specify a reasonable value for the count parameter, e.g. count: 1000
.
Warning
The platform in the cloud is only able to handle 10000
maximum count of elements! When the count goes over maximum the platform throws a 422
error code.
List all documents of a File Cabinet or Web Basket
C#
using System;
using System.Collections.Generic;
using System.Linq;
using DocuWare.Platform.ServerClient;
namespace DocuWare.PlatformClientExamples
{
static partial class Examples
{
public static List<Document> ListAllDocuments(ServiceConnection conn, string fileCabinetId, int? count = 10000)
{
DocumentsQueryResult queryResult = conn.GetFromDocumentsForDocumentsQueryResultAsync(
fileCabinetId,
count: count)
.Result;
List<Document> result = new List<Document>();
GetAllDocuments(queryResult, result);
foreach (Document document in result)
{
Console.WriteLine("Document {0} created at {1}", document.Id, document.CreatedAt);
}
return result;
}
public static void GetAllDocuments(DocumentsQueryResult queryResult, List<Document> documents)
{
documents.AddRange(queryResult.Items);
if (queryResult.NextRelationLink != null)
{
GetAllDocuments(queryResult.GetDocumentsQueryResultFromNextRelationAsync().Result, documents);
}
}
}
}
List all documents of a File Cabinet or Web Basket asynchronously
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<List<Document>> ListAllDocumentsAsync(ServiceConnection conn, string fileCabinetId, int? count = 10000)
{
DocumentsQueryResult queryResult = await conn.GetFromDocumentsForDocumentsQueryResultAsync(
fileCabinetId,
count: count)
.ConfigureAwait(false);
List<Document> result = new List<Document>();
await GetAllDocumentsAsync(queryResult, result);
foreach (Document document in result)
{
Console.WriteLine("Document {0} created at {1}", document.Id, document.CreatedAt);
}
return result;
}
public static async Task GetAllDocumentsAsync(DocumentsQueryResult queryResult, List<Document> documents)
{
documents.AddRange(queryResult.Items);
if (queryResult.NextRelationLink != null)
{
await GetAllDocumentsAsync(await queryResult.GetDocumentsQueryResultFromNextRelationAsync(), documents);
}
}
}
}