Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Grant Editing Permissions in a Document

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

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

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

rangePermissions.Add(rp);

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