# Document Protection and User Permissions

> What EditMode, DocumentPermissions and editable regions prevent in Windows Forms, why UserNames needs your sign-in, and how MasterPassword unlocks files.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for Windows Forms > Security > Document Protection and User Permissions
- **1982 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/security/document-protection/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/security/document-protection/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/security/document-protection/llms-full.txt

---

A protected document keeps users of your editor from changing what they shouldn't, and editable regions leave open exactly the parts a named user may fill in. That makes protection a good fit for forms, contracts and templates. It isn't access control, though: it doesn't hide the content, it depends on a password that someone has to keep, and the user names it relies on come from your application. Knowing these limits helps you decide where protection is enough and where a document needs more.

How to protect a document with the **Permissions** tab and in code is shown in [Document Protection and Editable Regions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/protection/llms-full.txt). The samples here use *Form1.cs* with an editor named `textControl1`.

### What Protection Consists of

Protection combines three settings of the `TextControl`: [EditMode](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/editmode-property/llms-full.txt) `ReadAndSelect`, optionally with `UsePassword`, turns the restrictions on, [DocumentPermissions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/documentpermissions-property/llms-full.txt) says what stays allowed, and editable regions stay open for everyone or for one user name. [How Document Protection Works](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/protection/#how-document-protection-works) describes each setting and the formats that save them. Text Control describes this protection as compatible with Microsoft Word.

### What Protection Guards Against

- **Changes in the editor.** Users of a `TextControl` can't edit or format a protected document beyond its permissions, and they can change only the editable regions that belong to them or to everyone.
- **Removing the protection without the password.** A document protected with a password opens read-only, and lifting the protection asks for the same password.
- **Actions your interface offers.** The built-in ribbon shows the permissions: after a document whose permissions don't allow formatting is loaded, its formatting buttons are disabled. Buttons and menu items of your own check the properties listed in [Check What the User May Do](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/protection/#check-what-the-user-may-do).

![A Windows Forms ribbon after a protected document was loaded, with the buttons of the Font group disabled.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/ribbon-disabled-protected.362a7748.webp)

### What Protection Doesn't Do

- **It doesn't hide the content.** A protected document opens read-only, so everybody who opens it can read it and select its text. For a confidential document, save it as a PDF with a user password, as [PDF Passwords and Permissions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/security/pdf-passwords/llms-full.txt) describes.
- **It isn't saved without a password.** Text Control's article on document permissions states that `EditMode` must be `ReadAndSelect` combined with `UsePassword` for the permissions to be saved in the document. Without a password, the restrictions apply in the current editor only, and setting `EditMode` back to `Edit` lifts them.
- **Whoever knows the password has full access.** The password of the protection is the master password of the document. Code that loads the document with this password in [MasterPassword](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/loadsavesettingsbase/masterpassword-property/llms-full.txt) of the `LoadSettings` gets it without restrictions.
- **It doesn't show whether a document was changed.** A document that was edited by someone who knew the password looks the same as the original. A digital signature makes changes to a PDF detectable, as [Certificate and Private Key Handling](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/security/certificates/llms-full.txt) describes.

### User Names Aren't Sign-Ins

An editable region belongs to a user name, and [UserNames](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/usernames-property/llms-full.txt) lists the users who work with the editor. When a document is read-only, the regions of these users can be edited. TX Text Control compares the names; it doesn't check who the user is. Whoever can set `UserNames`, or type a name into a box that your application passes on, can edit the regions of that name.

The TX Words sample *User Access*, installed with the setup, shows the difference. Before anyone signs in, only the region for all users is highlighted and editable:

![The Permissions tab with Enforce Protection active and only the paragraph editable by all users highlighted in green.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/permissions-signed-out.e0b052b7.webp)

The sample's **Sign In** command creates the account in a password dialog box of its own:

![The Create New User Account dialog box of the TX Words sample with the user John and a new password entered and confirmed.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/create-user-account-dialog.b68c5f15.webp)

After the user signs in with the application's own **Sign In** command and password dialog box, the sample sets `UserNames` to the name of the signed-in user, and that user's region is highlighted and editable as well:

![The same document after signing in as John, with the words general section highlighted as John's editable region.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/permissions-signed-in.488ba6c6.webp)

Set the names the same way, from the user your application has authenticated and never from a text box, and only then load the document, as [Open a Protected Document](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/protection/#open-a-protected-document) shows. The first name of the list is also the author of the comments and tracked changes the user creates. When users add names in the **Add Users** dialog box of the **Permissions** tab, [RegisteredUserNames](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-windows-forms-ribbon/ribbonpermissionstab/registeredusernames-property/llms-full.txt) and [AllowAddingUserNames](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-windows-forms-ribbon/ribbonpermissionstab/allowaddingusernames-property/llms-full.txt) limit them to the users of your application, as [Protect a Document With the Ribbon](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/protection/#protect-a-document-with-the-ribbon) shows.

### Process Protected Documents in Code

The protection password is what unlocks a document, for users and for code alike. Text Control's articles load a protected document with the password in `MasterPassword`, for example to convert it to PDF with a [ServerTextControl](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/servertextcontrol/llms-full.txt):

```csharp
private void exportContractButton_Click(object sender, EventArgs e)
{
    using (ServerTextControl tx = new ServerTextControl())
    {
        tx.Create();

        // The password of the protection lifts all restrictions
        LoadSettings loadSettings = new LoadSettings()
        {
            MasterPassword = protectionPassword
        };

        tx.Load("contract.tx", StreamType.InternalUnicodeFormat, loadSettings);
        tx.Save("contract.pdf", StreamType.AdobePDF);
    }
}
```

The code works as follows:

- [Create](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/servertextcontrol/create-method/llms-full.txt) initializes the `ServerTextControl` before any other member is used.
- `protectionPassword` is a field that holds the password. Get it from the user or from a protected store when it's needed, and don't write it into the source code: every copy of your application would contain it.
- Without the password, the document stays protected, and according to the article it can't be exported to PDF as it is.

The reference lists `MasterPassword` as a setting of PDF documents; the loading of other protected formats with it rests on Text Control's articles [Document Permissions and Password Encryption](https://www.textcontrol.com/blog/2019/07/05/document-permissions-and-password-encryption/) and [Exporting Password Protected Documents to PDF in .NET C#](https://www.textcontrol.com/blog/2024/10/28/exporting-password-protected-documents-to-pdf-in-net-c-sharp/).

### Choose the Right Protection

| Goal | Use |
|---|---|
| Users of your editor may change only certain parts | Document protection with editable regions |
| Nobody without a password may read the document | A PDF with a user password |
| Recipients can see whether the document was changed | A digitally signed PDF |
| Readers of a PDF shouldn't print or copy it | PDF permissions with a master password, and a user password when the content is confidential |

### Next Steps

- [Document Protection and Editable Regions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/protection/llms-full.txt): protect documents with the ribbon and in code.
- [PDF Passwords and Permissions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/security/pdf-passwords/llms-full.txt): protection that works outside your application.
- [Form Fields and Conditional Instructions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/form-fields/llms-full.txt): forms whose fields stay editable in a protected document.
- [Security Overview](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/security/overview/llms-full.txt): how document protection fits with the other mechanisms.

---

## Nearby

- **Previous:** [Security Overview](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/security/overview/llms-full.txt)
- **Next:** [Handling Untrusted Documents](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/security/untrusted-documents/llms-full.txt)
