officefileapi-118636-word-processing-document-api-examples-protection-how-to-grant-editing-permissions-in-a-document.md
This code snippet illustrates how to unlock specific document ranges in a protected document for authenticated users by doing the following:
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");
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")