# Document Properties

> Set and read title, subject, author, keywords and creation and modification dates of RTF, DOC and DOCX documents with the LoadSaveAttribute property.

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

---

Document properties describe or identify a document through metadata, such as its title, its subject or the name of its author. In rich text formats such as RTF, DOC and DOCX, `TXTextControl` sets and reads them with the [LoadSaveAttribute](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/loadsaveattribute-property/llms-full.txt) property, and a Visual Basic sample shows how a form edits them, saves them with a document and reads them back.

The code shown here is in the *Samples\\VB6\\DocProperties* sample source directory.

### How LoadSaveAttribute Works

`LoadSaveAttribute` sets and gets various attributes when a document is loaded or saved. You pass the attribute as a constant: set the value before you call [Save](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/save-method/llms-full.txt) to store it in the document, and read it after you call [Load](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/load-method/llms-full.txt) to get the value the document contains.

The sample uses these document properties:

| Constant | Document property |
|---|---|
| `txDocTitle` | Title |
| `txDocSubject` | Subject |
| `txAuthor` | Author |
| `txDocKeywords` | Keywords |
| `txCreationDate` | Creation date |
| `txLastModificationDate` | Date of last modification |

The [constants](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/loadsaveattribute-property/#constants) of `LoadSaveAttribute` list all attributes.

### Save the Document Properties

When the program starts, it sets a default value for each attribute, including the creation and modification dates, and shows the values in text boxes. The user can edit every value except the two dates, which are set automatically.

When the user clicks the **Save** button, the document properties are taken from the text boxes and assigned to the attributes:

```vbscript
Private Sub SaveButton_Click()

   ' Retrieve each attribute from the corresponding text box
   With TXTextControl1
      .LoadSaveAttribute(txDocTitle) = Text_Title.Text
      .LoadSaveAttribute(txDocSubject) = Text_Subject.Text
      .LoadSaveAttribute(txAuthor) = Text_Author.Text
      .LoadSaveAttribute(txLastModificationDate) = DateTime.Now
      .LoadSaveAttribute(txDocKeywords) = SetKeyWords(Text_Keywords.Text)
      ' Check if a creation date had already been through a load operation.
      ' If a creation date has not been set, use the current date and time.
      If (Text_CreationDate.Text = "") Then .LoadSaveAttribute(txCreationDate) = DateTime.Now
      .Save App.Path + "\Document_Properties.rtf", 0, 5, False
   End With

   ' Show message box to the user to make sure the Load button is clicked next.
   MsgBox "Document properties have been saved!" + vbCr + "Please click on the Load button.", vbOKOnly, "Document properties saved"

   ' Clear the text boxes once the document has been saved.
   Text_Title.Text = ""
   Text_Subject.Text = ""
   Text_Author.Text = ""
   Text_Keywords.Text = ""
   Text_ModDate.Text = ""
   Text_CreationDate.Text = ""
   ' Reset and clear the TXTextControl
   TXTextControl1.ResetContents

End Sub
```

The code works as follows:

- Each text box value is assigned to its `LoadSaveAttribute` constant.
- `txLastModificationDate` is set to the current system date and time on every save.
- `txCreationDate` is set to the current date and time only if no creation date was retrieved before, by a load operation. This way it isn't overwritten each time the document is saved.
- `Save` writes the document as RTF to *Document\_Properties.rtf* in the application directory.
- A message box tells the user to click the **Load** button next. Then the text boxes are cleared, and [ResetContents](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/resetcontents-method/llms-full.txt) clears `TXTextControl`.

### Load the Document Properties

When the user loads the document, its attributes are read from `LoadSaveAttribute` and assigned to the text boxes:

```vbscript
Private Sub LoadButton_Click()

   ' Retrieve each attribute from the loaded document
   With TXTextControl1
      .Load App.Path + "\Document_Properties.rtf", 0, 5, False
      Text_Title.Text = .LoadSaveAttribute(txDocTitle)
      Text_Subject.Text = .LoadSaveAttribute(txDocSubject)
      Text_Author.Text = .LoadSaveAttribute(txAuthor)
      Text_Keywords.Text = GetKeyWords(.LoadSaveAttribute(txDocKeywords))
      Text_ModDate.Text = .LoadSaveAttribute(txLastModificationDate)
      Text_CreationDate.Text = .LoadSaveAttribute(txCreationDate)
   End With

End Sub
```

### Convert the Keywords

Two helper functions of the sample convert between TAB-separated and comma-separated strings. Both take a string and return the converted string:

- **`GetKeyWords`** replaces all TAB characters of a string with commas. The sample uses it after loading, to show the keywords in a text box.
- **`SetKeyWords`** replaces all commas with TAB characters. The sample uses it before saving, to assign the keywords to `txDocKeywords`.

### Related Pages

- [Working with Files](https://docs.textcontrol.com/tx-text-control-activex/document-editor/load-save/llms-full.txt): the file formats `Load` and `Save` read and write.
- [PDF Export](https://docs.textcontrol.com/tx-text-control-activex/pdf/llms-full.txt): exporting documents to PDF.
- [Loading, Saving and Database Support](https://docs.textcontrol.com/tx-text-control-activex/reference/categories/load-save/llms-full.txt): the members that load and save documents.

---

## Nearby

- **Previous:** [File Drag and Drop](https://docs.textcontrol.com/tx-text-control-activex/document-editor/drag-drop/llms-full.txt)
- **Next:** [A Word Processor](https://docs.textcontrol.com/tx-text-control-activex/document-editor/word-processor/llms-full.txt)
