Available for: UI for ASP.NET MVC | UI for ASP.NET AJAX | UI for Blazor | UI for WPF | UI for WinForms | UI for Xamarin | UI for WinUI | UI for ASP.NET Core | UI for .NET MAUI

New to Telerik Document Processing? Download free 30-day trial

PermissionRange

A PermissionRange object holds annotation markers which specify for which range of document elements it refers. Every permission has a corresponding PermissionRangeStart and PermissionRangeEnd, which are inline elements. These two elements specify the range's location as follows.

  • PermissionRangeStart: Specifies the start of a permission annotation.
  • PermissionRangeEnd: Specifies the end of a permission annotation.

Inserting a PermissionRange

Creating a PermissionRange requires to pass an instance of the PermissionRangeCredentials class to the constructor, which can be created in either one of the following ways:

  • PermissionRangeCredentials(EditingGroup editingGroup): Initialize credentials with a type of user group. The enumeration exposes the following members:
    • None: Specifies that none of the users that open the document shall be allowed to edit range permissions using this editing group when document protection is enforced.
    • Everyone: Specifies that all users that open the document shall be allowed to edit range permissions using this editing group when document protection is enforced.
    • Administrators: Specifies that only user(s) who the viewing application associates with the Administrators group shall be allowed to edit the contents between the start and end permission ranges when document protection is enforced.
    • Contributors: Specifies that only user(s) who the viewing application associates with the Contributors group shall be allowed to edit the contents between the start and end permission ranges when document protection is enforced.
    • Editors: Specifies that only user(s) who the viewing application associates with the Editors group shall be allowed to edit the contents between the start and end permission ranges when document protection is enforced.
    • Owners: Specifies that only user(s) who the viewing application associates with the Owners group shall be allowed to edit the contents between the start and end permission ranges when document protection is enforced.
    • Current: Specifies that only user(s) who the viewing application associates with the Current group shall be allowed to edit the contents between the start and end permission ranges when document protection is enforced.
  • PermissionRangeCredentials(string editor): Initialize credentials by passing the single user's name, email or domain credentials.

The credentials you specify to a permission range are used by the consumer of the generated document and it is responsible for making sure they are enforced when the document is protected. A protected document can still be edited with the API of RadWordsProcessing.

Example 1 demonstrates how to create permission credentials for a single user specified by email and a permission range in a Paragraph.

Example 1: Add PermissionRange to paragraph

Table table = editor.InsertTable(); 
TableRow row = table.Rows.AddTableRow(); 
TableCell cell = row.Cells.AddTableCell(); 
cell.Blocks.AddParagraph().Inlines.AddRun("Hello"); 
 
PermissionRangeCredentials everyone = new PermissionRangeCredentials(EditingGroup.Everyone); 
PermissionRange range = editor.InsertPermissionRange(everyone, cell); 
The paragraph should belong to the same document that is passed to the constructor of the PermissionRange object, otherwise an exception is thrown.

Inserting a PermissionRange in the document can be achieved through RadFlowDocumentEditor as well. Since a permission range refers to a specific document element or a range of elements, there are several overloads for the InsertPermissionRange() method - accepting a TableCell, TableRow or two inline elements representing the start and end of the range.

Example 2 demonstrates how to specify that a TableCell can be edited by everyone when protection is enforced.

Example 2: Insert PermissionRange for TableCell

Table table = editor.InsertTable(); 
TableRow row = table.Rows.AddTableRow(); 
TableCell cell = row.Cells.AddTableCell(); 
cell.Blocks.AddParagraph().Inlines.AddRun("Hello"); 
 
PermissionRangeCredentials everyone = new PermissionRangeCredentials(EditingGroup.Everyone); 
PermissionRange range = editor.InsertPermissionRange(everyone, cell); 

Operating with Permission Ranges

Enforcing Protection

Including permission ranges in a document is not enough to protect them from editing, you also need to enforce the protection. Protecting and unprotecting a document is achieved with the Protect() and Unprotect() methods of RadFlowDocumentEditor respectively. When enforcing and stopping the protection you have the option to pass a string password to the methods and specify the type of editing restrictions using the ProtectionMode enumeration.

ProtectionMode exposes the following members:

  • NoProtection: Specifies that no editing restrictions are applied.
  • AllowComments: Specifies that working with comments is allowed in addition to editing in permission ranges.
  • ReadOnly: Specifies that editing is allowed only in permission regions by the users or groups that have permissions for edition. This mode is applied when ProtectionMode parameter is not passed to the Protect() method.

Example 3 shows how to protect and unprotect a document using the various overloads of the methods.

Example 3: Protect and unprotect document through RadFlowDocumentEditor

RadFlowDocumentEditor editor = new RadFlowDocumentEditor(new RadFlowDocument()); 
editor.Protect(String.Empty); 
 
if (editor.Unprotect(string.Empty)) 
{ 
    editor.Protect("s3cr3tp4ssw0rd", ProtectionMode.AllowComments); 
} 
 
editor.Unprotect(); 

The last call to the Unprotect() method in Example 3 will enforce protection of type NoProtection to the document. Protecting a document is intended to notify the user that changes are unadvised, but stopping the protection is still possible. The Unprotect(string password) overload is introduced for your convenience to use in your applications and returns a Boolean result of the action.

Modifying Document Protection Settings

RadFlowDocument exposes a property of type ProtectionSettings - ProtectionSettings. Enforcing protection directly through the document is possible by setting the Enforced property as demonstrated in Example 4.

Example 4: Enforce protection through RadFlowDocument

document.ProtectionSettings.Enforced = true; 
The settings provide a number of other modification options, including changing the algorithm used to protect the document with one of the predefined in the ProtectionAlgorithmNames enumeration.

See Also

In this article