Custom properties can be created to store additional information about the document in the document itself. These properties remain with a document and can be viewed by all MS Word users that open the document. Several property management servers provide data tracking capabilities to search for, sort, and track documents based on document properties.

Using TX Text Control X14 (Windows Forms, WPF and ASP.NET), custom properties can be set and retrieved using the SaveSettings and LoadSettings parameter in the Load and Save methods.

The new class UserDefinedPropertyDictionary contains all custom properties stored in a document. Supported value types are:

  • System.String
  • System.Boolean
  • System.Int32
  • System.Double

The following sample code shows how to add new custom properties to a document:

TXTextControl.UserDefinedPropertyDictionary userSettings =
new TXTextControl.UserDefinedPropertyDictionary();
userSettings.Add("CustomPropertyString", "Custom property string");
userSettings.Add("CustomPropertyInt32", 123);
userSettings.Add("CustomPropertyBoolTrue", true);
userSettings.Add("CustomPropertyBoolFalse", false);
userSettings.Add("CustomPropertyDouble", 123.232);
TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings() {
UserDefinedDocumentProperties = userSettings
};
textControl1.Save("test.rtf",
TXTextControl.StreamType.RichTextFormat,
saveSettings);
view raw test.cs hosted with ❤ by GitHub

Unlimited number of custom properties can be stored in the document formats MS Word (DOC), Office Open XML (DOCX), Rich Text Format (RTF) and the internal TX Text Control format (TX).

The following code snippet shows how to load and retrieve the custom properties stored in a document:

TXTextControl.LoadSettings loadSettings = new TXTextControl.LoadSettings();
textControl1.Load("test.rtf",
TXTextControl.StreamType.RichTextFormat,
loadSettings);
foreach (DictionaryEntry property in loadSettings.UserDefinedDocumentProperties) {
Console.WriteLine(property.Key + ": " + property.Value.ToString());
}
view raw test.cs hosted with ❤ by GitHub

Stay tuned for more information about the upcoming release X14!