Working with Editable Ranges
Working with Editable Ranges
This guide shows how to inspect and remove editable ranges – the regions Word’s “Restrict
Editing” feature exempts from a document’s overall editing restriction, optionally scoped to a
specific user or group – in Aspose.Words FOSS for .NET. An editable range is bracketed in
the document tree by a pair of marker nodes, EditableRangeStart and EditableRangeEnd, and
described as a whole by the EditableRange facade class.
Finding Editable Ranges in a Document
There is no single collection property for editable ranges; find them by walking the node tree.
CompositeNode.GetChildNodes(nodeType, isDeep) with NodeType.EditableRangeStart returns every
EditableRangeStart node in the document (or in a subtree, if called on a node other than
Document). Each EditableRangeStart.EditableRange property then returns the corresponding
EditableRange facade object.
The EditableRange Facade
EditableRange describes a single editable range as a whole: Id identifies it,
SingleUser optionally names a specific user allowed to edit it, and EditorGroup (an
EditorType value) optionally names an editing group instead. EditableRangeStart and
EditableRangeEnd return the pair of marker nodes that bracket the range in the document.
EditableRange.Remove() removes the editable range – lifting the editing restriction exemption
for that region, without deleting the document content inside it.
The Marker Nodes: EditableRangeStart and EditableRangeEnd
EditableRangeStart and EditableRangeEnd are sealed Node subclasses that mark the
boundaries of a range in the document’s content flow. EditableRangeStart.Id and
EditableRangeEnd.Id identify the range; EditableRangeStart.EditableRange reaches the facade
object directly, and EditableRangeEnd.EditableRangeStart reaches back to the corresponding
start marker. Being ordinary nodes, both support the standard Node members – ParentNode,
Document, PreviousSibling, NextSibling, and Remove() to delete the individual marker.
Restricting Access with EditorType
EditorType enumerates the editing groups an EditableRange.EditorGroup can reference:
Administrators, Contributors, Editors, Owners, Everyone, Current, None, and
Unspecified (also available as Default, an alias for Unspecified).
Tips and Best Practices
- Use
GetChildNodes(NodeType.EditableRangeStart, true)withisDeep: trueto find editable ranges anywhere in the document, not just among a node’s immediate children. - Read
EditableRange.SingleUserandEditorGrouptogether to determine who a range is restricted to – a range can be scoped to one specific user, one editing group, or neither. - Call
EditableRange.Remove()(on the facade) rather than removing theEditableRangeStartandEditableRangeEndmarker nodes individually, so both ends of the range are cleaned up consistently.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
| No editable ranges are found even though the document has restricted editing | Search used the default (shallow) GetChildNodes call | Pass isDeep: true so the search covers the entire document subtree |
| Removing an editable range doesn’t remove the enclosed text | EditableRange.Remove() only removes the range markers and the editing exemption, not the content between them | This is expected – delete the content separately if it also needs to go |
EditorGroup reads as Unspecified even though Word shows a named group | The range’s editor group in the source document maps to EditorType.Unspecified/Default rather than one of the named group values | Check SingleUser as well – the range may instead be scoped to an individual user |
FAQ
How do I find all editable ranges in a document?
Call Document.GetChildNodes(NodeType.EditableRangeStart, true), then read the EditableRange
property on each EditableRangeStart node returned.
How do I tell who is allowed to edit a given range?
Read EditableRange.SingleUser (a specific user) and EditableRange.EditorGroup (an
EditorType editing group) on the facade object.
How do I remove an editing restriction from part of a document?
Call Remove() on the EditableRange facade object for that range.
What’s the difference between EditableRangeStart.EditableRange and EditableRangeEnd.EditableRangeStart?
EditableRangeStart.EditableRange reaches the facade object describing the whole range directly.
EditableRangeEnd.EditableRangeStart reaches back to the corresponding start marker node, from
which EditableRange can then be reached.
API Reference Summary
| Class / Enum | Description |
|---|---|
EditableRange | Facade for one editable range: Id, SingleUser, EditorGroup, Remove() |
EditableRangeStart | Node marking the start of a range; Id, EditableRange |
EditableRangeEnd | Node marking the end of a range; Id, EditableRangeStart |
EditorType | Enum of editing groups: Administrators, Contributors, Editors, Owners, Everyone, Current, None, Unspecified/Default |