# Document Properties

> Get and set the title, author, keywords and user-defined properties of a WPF document with DocumentSettings, a XAML sidebar panel and SaveSettings.

- **Product:** TX Text Control .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for WPF > Document Editor > Document Properties
- **3289 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/properties/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/properties/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/properties/llms-full.txt

---

Title, author, subject and keywords, the creation date, the application that created a document and any properties you add yourself are stored inside the document file. They let a document management system find and sort documents without opening them, and they stay with a document when it is sent on. The WPF `TextControl` exposes them for the document the user is editing, a sidebar panel lets users change them, and the save settings decide what ends up in the file.

The code below belongs in *MainWindow.xaml.cs* of a window with a `TextControl` named `textControl1`, as built in [Load and Save Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/document-editor/load-save/llms-full.txt), and uses `using TXTextControl;`.

### What Document Properties Are

[DocumentSettings](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/documentsettings-property/llms-full.txt) of the WPF `TextControl` returns a [DocumentSettings](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/documentsettings/llms-full.txt) object for the current document. Loading a document fills it, and saving stores all of its values automatically. The class was introduced in version 29.0.

| Property | Contains | Without a value |
|---|---|---|
| [DocumentTitle](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/documentsettings/documenttitle-property/llms-full.txt) | The title | An empty string |
| [Author](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/documentsettings/author-property/llms-full.txt) | The author | An empty string |
| [DocumentSubject](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/documentsettings/documentsubject-property/llms-full.txt) | The subject | An empty string |
| [DocumentKeywords](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/documentsettings/documentkeywords-property/llms-full.txt) | The keywords, as a string array | `null` |
| [CreationDate](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/documentsettings/creationdate-property/llms-full.txt) | The creation date | January 1, 0001 |
| [CreatorApplication](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/documentsettings/creatorapplication-property/llms-full.txt) | The application that created the document | An empty string |
| [DocumentBasePath](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/documentsettings/documentbasepath-property/llms-full.txt) | A path added to the relative paths of images and hypertext links |  |
| [UserDefinedDocumentProperties](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/documentsettings/userdefineddocumentproperties-property/llms-full.txt) | The properties you define | `null` |
| [EmbeddedFiles](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/documentsettings/embeddedfiles-property/llms-full.txt) | Files embedded in a PDF document | `null` |

The three properties that can be `null` need a check before your code uses them.

### Show the Document Settings Panel

The WPF [Sidebar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/sidebar/llms-full.txt) has a panel for managing the settings of a document. In XAML, name the editor in the sidebar's [TextControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/sidebar/textcontrol-property/llms-full.txt) attribute and set [ContentLayout](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/sidebar/contentlayout-property/llms-full.txt) to `DocumentSettings`:

```xml
<Window x:Class="SampleApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:WPF="clr-namespace:TXTextControl.WPF;assembly=TXTextControl.WPF"
        Title="MainWindow" Height="450" Width="800">
    <DockPanel>
        <WPF:Sidebar x:Name="sidebar1"
                    DockPanel.Dock="Right"
                    HorizontalAlignment="Right"
                    TextControl="textControl1"
                    ContentLayout="DocumentSettings" />
        <WPF:TextControl x:Name="textControl1" />
    </DockPanel>
</Window>
```

The panel has text boxes for the title, author, subject and keywords (**Tags**), shows the creation date and lists user-defined properties, which **Add...** and **Delete** change. The creation date is set to the current date when the content of the editor is reset; for a loaded document, the panel shows the date stored in it. A further category lists the attachments of a PDF document, described in [Attachments](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/pdf/attachments/#let-users-manage-attachments-in-the-sidebar).

As with the toolbars, the sidebar refers to the `TextControl` by its name. The reference shows `TextControl` of the sidebar with the type `TextControl`, but in version 34.0 the property is a string: in code, assign `"textControl1"`, not the object. [Sidebar and Panels](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/ribbon-ui/sidebar/llms-full.txt) describes the other panels.

### Set the Properties in Code

The following `Click` handler sets the standard properties and three user-defined properties of the document in the editor:

```csharp
private void setPropertiesButton_Click(object sender, RoutedEventArgs e)
{
    DocumentSettings settings = textControl1.DocumentSettings;

    settings.DocumentTitle = "Quarterly Report";
    settings.Author = "Sales Department";
    settings.DocumentSubject = "Results of the third quarter";
    settings.DocumentKeywords = new string[] { "sales", "report", "Q3" };

    // null if the document has no user-defined properties yet
    UserDefinedPropertyDictionary properties =
        settings.UserDefinedDocumentProperties ?? new UserDefinedPropertyDictionary();

    SetProperty(properties, "Department", "Sales");
    SetProperty(properties, "Revision", 3);
    SetProperty(properties, "Approved", false);

    settings.UserDefinedDocumentProperties = properties;
}

private static void SetProperty(UserDefinedPropertyDictionary properties, string name, object value)
{
    if (properties.Contains(name))
    {
        properties.Remove(name);
    }

    properties.Add(name, value);
}
```

The code works as follows:

- **Standard properties** are plain assignments and are written to the file with the next save.
- **User-defined properties** live in a [UserDefinedPropertyDictionary](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/userdefinedpropertydictionary/llms-full.txt). Each name is a string of up to 255 characters, and each value a `string`, `bool`, `int` or `double`.
- **Replacing a value.** `SetProperty` checks with [Contains](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/userdefinedpropertydictionary/contains-method/llms-full.txt), removes the old entry with [Remove](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/userdefinedpropertydictionary/remove-method/llms-full.txt) and stores the new one with [Add](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/userdefinedpropertydictionary/add-method/llms-full.txt).

### Read the Properties After Loading

[DocumentLoaded](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/documentloaded-event/llms-full.txt) occurs when a new document has been loaded, and `DocumentSettings` then holds its values. Connect the handler in the constructor of the window, after `InitializeComponent`, with `textControl1.DocumentLoaded += textControl1_DocumentLoaded;`. The handler needs `using System.Collections;` and `using System.Diagnostics;`:

```csharp
private void textControl1_DocumentLoaded(object sender, EventArgs e)
{
    DocumentSettings settings = textControl1.DocumentSettings;

    Debug.WriteLine("Title: " + settings.DocumentTitle);
    Debug.WriteLine("Author: " + settings.Author);

    // null if the document has no keywords
    if (settings.DocumentKeywords != null)
    {
        Debug.WriteLine("Keywords: " + string.Join(", ", settings.DocumentKeywords));
    }

    if (settings.UserDefinedDocumentProperties != null)
    {
        foreach (DictionaryEntry property in settings.UserDefinedDocumentProperties)
        {
            Debug.WriteLine(property.Key + " = " + property.Value);
        }
    }
}
```

The dictionary enumerates `DictionaryEntry` objects with the name in `Key` and the value in `Value`; [Names](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/userdefinedpropertydictionary/names-property/llms-full.txt) returns just the names. The read-only properties of [LoadSettings](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/loadsettings/llms-full.txt), such as [DocumentTitle](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/loadsettings/documenttitle-property/llms-full.txt) and [UserDefinedDocumentProperties](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/loadsettings/userdefineddocumentproperties-property/llms-full.txt), return the values of a single load operation, which is useful with a `ServerTextControl` that has no editor.

### Override Values When Saving

Values passed in a [SaveSettings](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/llms-full.txt) object take precedence over `DocumentSettings` when the document is saved. `SaveSettings` has [Author](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/author-property/llms-full.txt), `DocumentTitle`, `DocumentSubject`, `DocumentKeywords`, `CreationDate`, [LastModificationDate](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/lastmodificationdate-property/llms-full.txt), [CreatorApplication](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/creatorapplication-property/llms-full.txt) and [UserDefinedDocumentProperties](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/userdefineddocumentproperties-property/llms-full.txt):

```csharp
SaveSettings saveSettings = new SaveSettings()
{
    CreatorApplication = "My Editor",
    LastModificationDate = DateTime.Now
};

textControl1.Save("report.docx", StreamType.WordprocessingML, saveSettings);
```

The blog article [Maintaining Custom Document Properties](https://www.textcontrol.com/blog/2020/02/18/maintaining-custom-document-properties/) from 2020 passes user-defined properties with `SaveSettings` on every save, because they weren't kept otherwise. Since `DocumentSettings` arrived in version 29.0, the editor keeps them, and `SaveSettings` only replaces them.

### Which Formats Store the Properties

- **Title, author, subject, keywords, dates and creator application** can be saved with all supported text formats since version 23.0.
- **User-defined properties** are saved and loaded with the TX Text Control format, RTF, DOC and DOCX.
- **PDF documents** keep the standard properties as metadata; see [Document Metadata](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/pdf/metadata/llms-full.txt).
- **Embedded files** exist only in PDF and PDF/A documents; see [Attachments](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/pdf/attachments/llms-full.txt).

### Next Steps

- [Loading and Saving Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/load-save/llms-full.txt): the load and save options around the properties.
- [Sidebar and Panels](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/ribbon-ui/sidebar/llms-full.txt): the sidebar and its panels.
- [Document Metadata](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/pdf/metadata/llms-full.txt): properties of PDF documents.

---

## Nearby

- **Previous:** [Loading and Saving Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/load-save/llms-full.txt)
- **Next:** [Editing Text](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/editing-text/llms-full.txt)
