Products Technologies Demo Docs Blog Support Company

Document Permissions and Password Encryption

TX Text Control supports MS Word compatible document protection with granular permissions for formatting and read-only restrictions. Documents are encrypted with user and master passwords, and the ribbon automatically reflects the applied permission constraints on its UI controls.

Document Permissions and Password Encryption

TX Text Control allows you to protect documents with specific permissions and to protect documents from editing and formatting actions. Typically, a document is protected, exceptions are applied for specific users and the document is encrypted with a password. When opening such a document with TX Text Control without providing the master password, the permissions are applied and the document is protected automatically when the TXTextControl.TextControl.EditMode property is set to ReadAndSelect.

But the document permissions can be also used without encrypting the document. The following code shows how to prevent users from making formatting changes. The document content can be changed, but formatting actions are not allowed:

textControl1.DocumentPermissions.AllowFormatting = false;
textControl1.EditMode = TXTextControl.EditMode.ReadAndSelect;

If you want to save the permission settings in the document, the EditMode property must be set to ReadAndSelect and UsePassword. The document is then encrypted and the permissions are stored in the document.

textControl1.DocumentPermissions.AllowFormatting = false;
textControl1.EditMode = TXTextControl.EditMode.ReadAndSelect | EditMode.UsePassword;
textControl1.Save("test.tx", TXTextControl.StreamType.InternalUnicodeFormat);

If this document is re-opened and and the EditMode is set to ReadAndSelect, the permissions are automatically applied:

textControl1.Load("test.tx", TXTextControl.StreamType.InternalUnicodeFormat, ls);
textControl1.EditMode = TXTextControl.EditMode.ReadAndSelect;

The included ribbon bar of TX Text Control is reflecting these document permissions automatically. After reloading the document into TX Text Control, the formatting options are disabled:

Document Protection

The document master password can also be set programmatically when loading the document. The following code shows how to save a read-only document with formatting restrictions:

textControl1.DocumentPermissions.AllowFormatting = false;
textControl1.DocumentPermissions.ReadOnly = true;
textControl1.EditMode = TXTextControl.EditMode.ReadAndSelect | EditMode.UsePassword;
textControl1.Save("test.tx", TXTextControl.StreamType.InternalUnicodeFormat);

If this document is loaded without passing a password, the document cannot be edited or formatted. But if the document is opened with the correct master password, these restrictions are suspended:

LoadSettings ls = new LoadSettings()
{
    MasterPassword = "123"
};

textControl1.Load("test.tx", TXTextControl.StreamType.InternalUnicodeFormat, ls);
textControl1.EditMode = TXTextControl.EditMode.ReadAndSelect;

If you want to learn more about document protection, these 2 articles explain the basics of document protection:

Protected Documents Explained Simply

Protected Documents Explained Simply - Part II

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Also See

This post references the following in the documentation:

  • TXTextControl.TextControl.EditMode Property

Windows Forms

Text Control combines the power of a reporting tool and an easy-to-use WYSIWYG word processor - fully programmable and embeddable in your Windows Forms application. TX Text Control .NET for Windows Forms is a royalty-free, fully programmable rich edit control that offers developers a broad range of word processing features in a reusable component for Visual Studio.

See Windows Forms products

Related Posts

Windows FormsGetting StartedTutorial

Windows Forms Tutorial: Create Your First Windows Forms C# Application

This tutorial shows how to create your first Windows Forms application with C# using TX Text Control .NET for Windows Forms in Visual Studio 2022.


Windows FormsGetting StartedTutorial

Creating Your First Windows Forms Application with C#

This tutorial walks through creating a Windows Forms application with TX Text Control .NET for Windows Forms in C# on .NET 6. It covers installing the SDK via NuGet, adding TextControl from the…


Windows FormsTutorial

Creating A Windows Forms Ribbon Application

This tutorial walks through building a Windows Forms ribbon application with TX Text Control .NET for Windows Forms, covering ribbon tab configuration, contextual tab groups for table and frame…


Windows FormsDocument ProtectionRelease

X15: Protected Documents Explained Simply - Part II

TX Text Control X15 uses EditableRegion objects to define editable sections inside protected documents. Each region accepts a UserName that restricts editing to a specific user. The…


Windows FormsDocument ProtectionRelease

X15: Protected Documents Explained Simply

TX Text Control X15 supports password-based document protection via the EditMode property. Setting UsePassword combined with ReadAndSelect encrypts the document. When the file loads with EditMode…

Share on this blog post on: