Skip to main content

Document Protection

  • 3 minutes to read

The Rich Text Editor allows you to protect a document from accidental modifications. The controls allows you password-protect the entire document or parts of it. You can also specify permissions for individual users or user groups.

See online demo: Rich Text Editor - Document Protection

Document Protection

Protect a Document

You can protect a document with a password and make it read-only. The table below list members that allow you to manage document protection.

Member Description
checkProtectionPassword(password) Checks whether the specified password was used to protect the document.
isProtected Indicates whether the document is protected.
protect(password) Protects the document with the specified password.
unprotect Clears document protection.
function protectDocument() {
  if (!richEdit.document.isProtected) {
      const password = window.prompt('Enter new password(optional):', '');
  if (password !== undefined && password !== null)
      richEdit.document.protect(password);
  }
}
function unprotectDocument() {
  const password = window.prompt('Enter password:', '');
  if (password !== undefined && password !== null) {
      if (richEdit.document.checkProtectionPassword(password))
          richEdit.document.unprotect();
      else
          window.alert('The password incorrect');
  }
}

Specify Editable Document Ranges

The Rich Text Editor stores editable ranges as objects of the RangePermission type in the RangePermissionCollection collection. The table below lists methods that allow you to manage the collection.

Method Description
create(interval, userName, group) Creates a range permission that allows a user/group to edit the specified interval.
protectRange(intervals, userName, group) Creates range permissions that protect the specified intervals from being edited.
delete Deletes the range permission.
find(options) Returns a range permission array that matches the specified options.

A range permission can be specified for a user or a user group.

Predefined Groups

The Rich Text Editor defines several predefined groups: administrators, contributors, current, editors, everyone, and owners. Permissions set for everyone apply to all users. Other groups have no special meaning and you can associate them with different users.

Note

If you work with RTF files, remember that this format only keeps predefined groups. Other formats allow you to create custom group definitions.

var document = richEdit.document;
document.rangePermissions.create(document.interval, 'projectmanager@somecompany.com');
document.rangePermissions.create(document.paragraphs.getByIndex(10).interval, '', 'everyone');
document.rangePermissions.protectRange([document.paragraphs.find(6).interval], '', 'editors');

Authenticate a User

The Rich Text Editor authorizes range modification if one of the user’s credentials meets the range’s permission requirements.

Use the following authentication options to specify user credentials:

.NET Core Server Settings Client Settings Runtime Settings Description
Authentication(Action<AuthenticationSettingsBuilder>) authentication authenticationOptions Provides access to authentication settings.
Group(String) group group Specifies the name of the group of users with editing permission.
UserName(String) userName userName Specifies the username with editing permission.

If a protected document includes a range permitted for a user group named everyone, every user can edit this text area even if the authentication settings are not defined.

@(Html.DevExpress().RichEdit("richEdit")
    .Authentication(a => { a
        .UserName("projectmanager@somecompany.com")
        .Group("editors");
    })
)

Highlight Available Ranges

The Rich Text Editor highlights and encloses editable ranges in brackets. You can control the visibility and color of the highlight and brackets.

Document Protection

.NET Core Server Settings Client Settings Runtime Settings Description
ShowBrackets(Boolean) showBrackets showBrackets Indicates whether the brackets that start and the end an editable range are visible.
BracketsColor(Color) bracketsColor bracketsColor Specifies the color of the range brackets.
HighlightRanges(Boolean) highlightRanges highlightRanges Indicates whether the editable range is highlighted.
HighlightColor(Color) highlightColor highlightColor Specifies the highlight color.
@(Html.DevExpress().RichEdit("richEdit")
    .RangePermissions(rp => rp
        .ShowBrackets(true)
        .BracketsColor(System.Drawing.Color.Blue)
        .HighlightRanges(true)
        .HighlightColor(System.Drawing.Color.LightGreen)
    )
)