Restrict editing in Blazor DocumentEditor Component
1 Jul 20261 minute to read
This Blazor DOCX Editor (Document Editor) provides 2 types of restriction for editing:
- Read-only: Allows all the users to view the document contents but not make changes to it.
- Allows changes to certain portion of the document: Allows the users to edit to certain portion of the document.
Read only
The following code example shows how to restrict or protect editing for the entire content (show as read-only).
@using Syncfusion.Blazor.DocumentEditor
<button @onclick="ReadOnly">Read Only</button>
<SfDocumentEditorContainer @ref="container" EnableToolbar=true></SfDocumentEditorContainer>
@code {
SfDocumentEditorContainer container;
public void ReadOnly(object args)
{
container.RestrictEditing = true;
}
}Protect document with editable region
User can select a specific section and mark it as an editable region, allowing modification only in that part. The rest of the document remains protected from any changes.
Insert editable region
Use the InsertEditingRegionAsync method to mark specific paragraphs as editable.This allows you to control editing by giving access to all users
The following example shows how to insert an editable region.
container.DocumentEditor.Editor.InsertEditingRegionAsync();Highlight color for editable region
The UserColor property can be used to highlight the editable region of the current user.
The following code example demonstrates how to set the userColor.
<SfDocumentEditorContainer UserColor="#FFFF00"></SfDocumentEditorContainer>Enable or disable editable region highlighting
The HighlightEditableRanges property can be used to toggle the highlighting of editable regions.
The following code example demonstrates how to enable or disable editable region highlighting.
<SfDocumentEditorContainer DocumentEditorSettings="@settings"></SfDocumentEditorContainer>
@code {
public DocumentEditorSettingsModel settings = new DocumentEditorSettingsModel() { HighlightEditableRanges = false };
}Online Demo
Explore how to restrict editing and protect Word documents using the Blazor Document Editor in this live demo here.