Products Technologies Demo Docs Blog Support Company

Document Permissions and Password Encryption

This article explains how to set document permissions and how to open encrypted documents programmatically.

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 Windows Forms tutorial shows how to create your first desktop application with C# using TX Text Control .NET for Windows Forms.


Windows FormsTutorial

Creating A Windows Forms Ribbon Application

This tutorial shows how to create a Windows Forms ribbon application with TX Text Control .NET for Windows Forms.


Windows FormsDocument ProtectionRelease

X15: Protected Documents Explained Simply - Part II

This article explains the document protection feature in an easy to understand way focused on the editable regions.


Windows FormsDocument ProtectionRelease

X15: Protected Documents Explained Simply

This article explains the document protection feature in an easy to understand way.