Howto: Use Document Permissions

This chapter explains the typical workflow when working with document permissions and user specific editable regions.

The source code for this example is contained in the following directories:

  • %USERPROFILE%\My Documents\TX Text Control 29.0.NET for WPF\Samples\WPF\VB.NET\Permissions\Workflow
  • %USERPROFILE%\My Documents\TX Text Control 29.0.NET for WPF\Samples\WPF\CSharp\Permissions\Workflow

Used TX Text Control controls:

  • TXTextControl.WPF.TextControl

Relevant API Links

User Administration

The sample consists of 3 parts:

  • User Administration
  • Design Document as Administrator
  • Open Document as Specific User

Image

In the first step, users can be created and deleted. An administrator or designer of a document can choose from these created users to create editable regions in a protected document. This sample shows how to create a list of users for demo purposes. In real-world applications, these users would be created by your user management layer in your application (Windows users, Sharepoint users or any other authorized list of users).

Open the application and click on Manage Users. In the opened dialog, click New... to add a new user. Choose a Username, type in a Password, repeat this password and confirm with OK. Repeat this step with as many users as you like.

Image

Close the Manage Users dialog by clicking OK.

Design Document as Administrator

In step 2, an instance of the TX Text Control editor is opened with full editing permissions to design a document with editable regions. The list of user names is passed to the editor form and is applied to the WPF.RibbonPermissionsTab.RegisteredUserNames property of the RibbonPermissionsTab:

ribbonPermissionsTab1.RegisteredUserNames = m_sRegisteredUserNames;
ribbonPermissionsTab1.RegisteredUserNames = m_sRegisteredUserNames

Image

Click on Design Document to open the editor form. In the opened editor form, click on Read Only from the Restrict Editing ribbon group in the Permissions ribbon tab.

Click the Add Users button in the Mark Exceptions and set Users ribbon group.

Image

In the opened dialog Add Users, open the drop-down box, select a user and add the user by clicking Add. Add as many users as you like and confirm with OK.

Image

Now select a paragraph in the document that represents an exception in a protected document. Select the user(s) from the list view in the Mark Exceptions and set Users ribbon group. The selected text gets highlighted with a different color representing different users.

To enable the protection, click Enforce Protection and type in a master password which is used to encrypt the document. Reenter the password and confirm with OK.

Close the form by choosing Close Editor from the application main menu File. The document is saved automatically.

Open Document as Specific User

This step shows how the protected document is opened as a specific user with limited document access. Click on Open Document and choose the user from the drop-down box in the opened dialog:

Image

Type in the user password and confirm with OK.

In this case, an editor form is opened with limited document permissions. In order to enable this user mode, the usernames can be passed to TextControl using the TextControl.UserNames property. When a document is set to read-only, all editable regions that are related to these users can be edited.

textControl1.UserNames = new string[] { m_username };
textControl1.EditMode = TXTextControl.EditMode.ReadAndSelect;
textControl1.UserNames = New String() {m_username}
textControl1.EditMode = TXTextControl.EditMode.ReadAndSelect

Image

The editor has been opened in a user mode for a specific user. The document itself is protected and editable regions are highlighted. The logged in user is able to navigate through associated editable regions. The content of those regions are editable while the rest of the document is read only.

When toggling the Enforce Protection toggle button, the user needs to type in the document master password. This master password can be used to unlock the document.q