In a Word document, we are tracking changes user has made, and at the end we are accepting it. We want to disable/lock the sections or parts of document where user have done changes in word document. In other sections of document, user can continue editing.
To lock or disable editing in specific sections of a Word document where changes have been accepted, while allowing editing in other sections, you can utilize the document protection features provided by Aspose.Words for .NET. Here’s how you can achieve this:
-
Protect the Document: First, you need to apply protection to the document. You can set the protection type to allow only form fields or read-only access.
-
Set Section Protection: After applying document protection, you can selectively enable or disable protection for specific sections. By default, all sections will be protected, but you can turn off protection for the sections where you want to allow editing.
Here’s a sample code snippet demonstrating how to implement this:
using Aspose.Words;
using Aspose.Words.Editing;
using Aspose.Words.Protection;
class Program
{
static void Main()
{
// Create a new document
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add content to the document
builder.Writeln("Section 1. This section will be editable.");
builder.InsertBreak(BreakType.SectionBreakNewPage);
builder.Writeln("Section 2. This section will be protected.");
// Apply protection to the document
doc.Protect(ProtectionType.AllowOnlyFormFields, "password");
// Disable protection for the first section
doc.Sections[0].ProtectedForForms = false;
// Save the document
doc.Save("ProtectedDocument.docx");
}
}
Explanation:
- Document Creation: A new document is created, and content is added to two sections.
- Protection Application: The document is protected to allow only form fields.
- Section Protection: The first section’s protection is disabled, allowing users to edit it freely, while the second section remains protected.
- Saving the Document: Finally, the document is saved with the specified name.
This approach allows you to manage which parts of the document can be edited after accepting tracked changes, ensuring that only the desired sections remain editable while others are locked [1].
References:
We want to lock/disable only the part of the document where user have made changes and those changes are accepted.
@chetna.solanki Could you please create the expected output document in MS Word and attach it here for our reference? You should note that Aspose.Words is limited to document format features. So if document format specification does not allow to achieve something, this cannot be achieved using Aspose.Words too.
Test Document.docx (17.5 KB)
In attached document, there are red line changes, only those sections, we need to disable/lock after those changes accepted.
@chetna.solanki As I can see the provided document can be edited. So it is not quite clear what you would like to achieve. Can you achieve your requirements in MS Word?