Back to Devexpress

How to: Grant Editing Permissions in a Document

officefileapi-118636-word-processing-document-api-examples-protection-how-to-grant-editing-permissions-in-a-document.md

latest2.6 KB
Original Source

How to: Grant Editing Permissions in a Document

  • Sep 19, 2023

This code snippet illustrates how to unlock specific document ranges in a protected document for authenticated users by doing the following:

  1. Access the document collection of ranges with permissions by calling the SubDocument.BeginUpdateRangePermissions method.
  2. Call the RangePermissionCollection.CreateRangePermission method to create a RangePermission instance to the target document range.
  3. Specify the user and/or the group of users that are eligible to edit the document using the RangePermission.Group and RangePermission.UserName properties.
  4. Finish the update by calling the SubDocument.EndUpdateRangePermissions method.

View Example

csharp
server.LoadDocument("Documents//Grimm.docx", DocumentFormat.Docx);
Document document = server.Document;

// Protect document range
RangePermissionCollection rangePermissions = document.BeginUpdateRangePermissions();
RangePermission rp = rangePermissions.CreateRangePermission(document.Paragraphs[3].Range);
rp.Group = "Administrators";
rp.UserName = "[email protected]";

rangePermissions.Add(rp);

document.EndUpdateRangePermissions(rangePermissions);
// Enforce protection and set password.
document.Protect("123");
vb
server.LoadDocument("Documents//Grimm.docx", DocumentFormat.Docx)
Dim document As Document = server.Document

' Protect document range
Dim rangePermissions As RangePermissionCollection = document.BeginUpdateRangePermissions()
Dim rp As RangePermission = rangePermissions.CreateRangePermission(document.Paragraphs(3).Range)
rp.Group = "Administrators"
rp.UserName = "[email protected]"

rangePermissions.Add(rp)

document.EndUpdateRangePermissions(rangePermissions)
' Enforce protection and set password.
document.Protect("123")