.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+

RangePermission Class

Represents a document range for which editing permissions are set.

Namespace: DevExpress.XtraRichEdit.API.Native

Assembly: DevExpress.RichEdit.v19.2.Core.dll

Declaration

[ComVisible(true)]
public class RangePermission
<ComVisible(True)>
Public Class RangePermission
[ComVisible(true)]
public class RangePermission
<ComVisible(True)>
Public Class RangePermission
[ComVisible(true)]
public class RangePermission
<ComVisible(True)>
Public Class RangePermission

Remarks

While a document is protected, a range permission limits editing to a collection of users and user groups. Editable sections can be displayed with highlighting or enclosed in brackets.

Call the SubDocument.BeginUpdateRangePermissions method to retrieve the collection of range permissions.

Set the RichEditControlOptionsBase.Authentication property to the current user name to make the range editable. Edit permission for a range requires one of the following to be true:

Use the RichEditControlOptionsBase.RangePermissions property to set range highlighting and bracket options. Call the Document.Protect and Document.Unprotect methods to enable and disable document protection, respectively. These methods do not require user input. A password can be passed as an argument to the Document.Protect method to protect the document. Calling the Document.Unprotect method disables protection without the need for a password. To prompt the user for a password, execute the ProtectDocumentCommand and the UnprotectDocumentCommand commands instead.

This code snippet demonstrates how you can fetch usernames assigned to protected ranges in a document and identify the current user as being one of the particular users. It allows you to edit the range with editing permissions granted to that user.

The SubDocument.BeginUpdateRangePermissions method is used to get all permissions for document ranges. Call the SubDocument.CancelUpdateRangePermissions if you do not intend to modify them.

Then, we traverse the collection of range permissions and obtain user names via the RangePermission.UserName property. The ComboBoxEdit control is filled with the names, so an existing name can be selected to log in.

To log in (i.e. to specify the user whose permissions will be in effect), the RichEditControlOptionsBase.Authentication options are used.

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.XtraRichEdit.Services;
        void richEditControl1_DocumentLoaded(object sender, EventArgs e)
        {
            UpdateUserNameLoginCombo();
            richEditControl1.Options.Authentication.UserName = String.Empty;
        }
        private void UpdateUserNameLoginCombo()
        {
            cmbUserName.SelectedValueChanged-=cmbUserName_SelectedValueChanged;
            RangePermissionCollection rangePermissions = richEditControl1.Document.BeginUpdateRangePermissions();
            richEditControl1.Document.CancelUpdateRangePermissions(rangePermissions);
            List<String> users = new List<string>();
            foreach (RangePermission rangePermission in rangePermissions)
            {
                string userName = rangePermission.UserName;
                if (users.Contains(userName))
                    continue;
                if (!String.IsNullOrEmpty(userName))
                    users.Add(userName);
            }
            cmbUserName.Properties.BeginUpdate();
            cmbUserName.Properties.Items.Clear();
            cmbUserName.Properties.Items.Add(String.Empty);
            cmbUserName.Properties.Items.AddRange(users);
            foreach (MyUser user in myUserList) {
                if (!users.Contains(user.UserName)) cmbUserName.Properties.Items.Add(user.UserName);
            }
            cmbUserName.SelectedIndex = 0;
            cmbUserName.Properties.EndUpdate();
            cmbUserName.SelectedValueChanged += cmbUserName_SelectedValueChanged;
        }

        private void cmbUserName_SelectedValueChanged(object sender, EventArgs e)
        {
            string username = cmbUserName.SelectedItem.ToString();
            richEditControl1.Options.Authentication.UserName = username;
            MyUser myuser = myUserList.Find(s => s.UserName == username);
            richEditControl1.Options.Authentication.Group = (myuser != null) ? myuser.Group : String.Empty;

        }

Inheritance

Object
RangePermission
See Also