Application Properties
The two samples below show how to store, get, update and delete application properties.
Some DocuWare client applications may need to store additional information. This could be achieved by storing that information as application properties on document level or on section level.
Warning
The application properties which are stored on documentation level throught the API are stored on the first section of the document.
How the application properties are treated on some document operations:
- Clip - each document presorves its own application properties
- UnClip - each document preserves its own application properties
- Staple - only the application properties of the first section of the first document are preserved
- UnStaple - the application properties are set to all newly created documents
- Split - the application properties are set to all newly created documents
- CheckOut - the application properties of the first section are preserved
- CheckIn - the application properties of the two documents are merged
Store, Update and Delete Application Properties
C#
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocuWare.Platform.ServerClient;
namespace DocuWare.PlatformClientExamples
{
static partial class Examples
{
/// <summary>
/// Stores, gets, updates and deletes application properties on document level.
/// </summary>
public static void ApplicationProperties(Document newDocument, FileCabinet cabinet)
{
FileInfo[] filesInfo = new FileInfo[] { new FileInfo("2Pages.pdf"), new FileInfo("2Pages.pdf")};
// add application properties on upload
newDocument.ApplicationProperties = new List<DocumentApplicationProperty>();
newDocument.ApplicationProperties.Add(new DocumentApplicationProperty() { Name = "key1", Value = "Best Value" });
newDocument.ApplicationProperties.Add(new DocumentApplicationProperty() { Name = "key2", Value = "For Delete" });
// upload the document and retrieve it
newDocument = cabinet.UploadDocument(newDocument, filesInfo);
newDocument = newDocument.GetDocumentFromSelfRelation();
DocumentApplicationProperties properties = new DocumentApplicationProperties();
properties.DocumentApplicationProperty = new List<DocumentApplicationProperty>();
// update application properties
properties.DocumentApplicationProperty.Add(new DocumentApplicationProperty() { Name = "key1", Value = "UpdatedValue" });
properties.DocumentApplicationProperty.Add(new DocumentApplicationProperty() { Name = "key3", Value = "NewValue" });
// delete existing application property
properties.DocumentApplicationProperty.Add(new DocumentApplicationProperty() { Name = "key2", Value = null });
// update application properties
newDocument.PostToAppPropertiesRelationForDocumentApplicationProperties(properties);
}
/// <summary>
/// Stores, gets, updates and deletes application properties on section level.
/// </summary>
public static void ApplicationProperties(Section section, FileCabinet cabinet)
{
// add application properties on upload
DocumentApplicationProperties appProperties = new DocumentApplicationProperties();
appProperties.DocumentApplicationProperty = new List<DocumentApplicationProperty>();
appProperties.DocumentApplicationProperty.Add(new DocumentApplicationProperty() { Name = "key1", Value = "Best Value" });
appProperties.DocumentApplicationProperty.Add(new DocumentApplicationProperty() { Name = "key2", Value = "For Delete" });
section.PostToAppPropertiesRelationForDocumentApplicationProperties(appProperties);
// get application properties
appProperties = section.GetDocumentApplicationPropertiesFromAppPropertiesRelation();
// update application properties
appProperties.DocumentApplicationProperty.Add(new DocumentApplicationProperty() { Name = "key1", Value = "UpdatedValue" });
appProperties.DocumentApplicationProperty.Add(new DocumentApplicationProperty() { Name = "key3", Value = "NewValue" });
section.PostToAppPropertiesRelationForDocumentApplicationProperties(appProperties);
// delete existing application property - this will delete "key2" record
appProperties.DocumentApplicationProperty.Add(new DocumentApplicationProperty() { Name = "key2", Value = null });
section.PostToAppPropertiesRelationForDocumentApplicationProperties(appProperties);
}
}
}