ServerTextControl
Not every document your application handles has to be shown on screen. ServerTextControl creates, converts and merges documents in code, with the same programming interface as TextControl but without a window, and hands the result to the editor when the user should see it. What follows introduces when a desktop application uses it, the pattern every use follows and its key members.
What ServerTextControl Is
ServerTextControl is a component that provides the word processing features of TX Text Control without a user interface. The class is TXTextControl.ServerTextControl, derived from System.ComponentModel.Component rather than from Control, so it needs no form and is never visible.
Its programming interface is that of TextControl: the same Load and Save methods, the same Selection, and the same collections of tables, images, fields and other elements. Code that builds or changes a document works with either class.
When a Desktop Application Uses It
A desktop application uses ServerTextControl for documents the user doesn't watch being made: it builds or merges a document before the editor shows it, converts or prints files in the background, or runs a MailMerge while the editor shows something else. Without a user interface, it keeps no undo history and renders nothing for the screen, so it needs less time and memory than a TextControl for the same work.
How You Work With It
Every use follows the same pattern: create an instance in a using statement, call Create before any other member, load or build the document, and save it. A document moves to the editor as a byte array, because TextControl has the same byte array overloads of Load and Save.
Using ServerTextControl in Desktop Applications shows this pattern in code, passes documents between the two classes, runs long work on a background thread and merges templates without the editor. Create a Document Programmatically in Getting Started builds a first document.
The format is given as a StreamType for a file or a stream, a BinaryStreamType for a byte array and a StringStreamType for a string. Supported File Formats lists the values.
Key Members
| Member | Purpose |
|---|---|
| Create | Initializes a new instance. It must be called before the object is used. |
| Load | Loads a document and replaces the complete contents. |
| Append | Adds a document to the end of the existing one. |
| Save | Saves the complete document in the specified format. |
| Text | Gets or sets the text of the document. |
| Selection | The current selection, used to insert text and to apply formatting. |
| Tables, Images, HeadersAndFooters | The tables, images, headers and footers of the document. |
| ApplicationFields | Fields such as MS Word merge fields. LoadSettings.ApplicationFieldFormat must be set before loading, otherwise the collection is empty. |
| FormFields, Comments, TrackedChanges | The form fields, comments and tracked changes. |
Prints the document with a PrintDocument, without showing it. | |
| EntryAssembly | A static property that sets the assembly which licenses ServerTextControl, for example when it is used in a class library. |
The ServerTextControl reference lists all members.
Next Steps
- Create a Document Programmatically: a first document built in code.
- Using ServerTextControl in Desktop Applications: background work, threads and the editor in detail.
- Document Processing: creating, loading, saving and changing documents in code.
- MailMerge: merge templates with data in a
ServerTextControl.