Make Certain sections of word documents Read Only

Hi,
When building a word document, is it possible to make certain sections of the word document as read-only?
Thanks,
Vishal

Hello

Thanks for your interest in Aspose.Words. Using Aspose.Words you can protect whole document or a particular section of a document. Please follow the link to learn how to protect documents using Aspose.Words:
https://reference.aspose.com/words/net/aspose.words/section/protectedforforms/
Best regards,

Hi,
I am having problems with protecting the form fields using ProtectedForForms Property.
I’ve tried to implement protection using the following code:

protected void CreateDocument()
{
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    string html1 = "<p>Para1</p>";
    string html2 = "<p>Para2</p>";
    string html3 = "<p><b>Para3</b></p>";
    doc.Protect(ProtectionType.AllowOnlyFormFields);
    builder.InsertHtml(html1);
    builder.InsertBreak(BreakType.SectionBreakContinuous);
    // Code to insert HTML formatted text into a form field
    FormField frmField = builder.InsertTextInput("Para2", TextFormFieldType.Regular, "", "", 0);
    builder.MoveTo(frmField.NextSibling.NextSibling);
    builder.InsertHtml(html2);
    // Make the current section editable
    builder.CurrentSection.ProtectedForForms = false;
    builder.InsertBreak(BreakType.SectionBreakContinuous);
    frmField = builder.InsertTextInput("Para3", TextFormFieldType.Regular, "", "", 0);
    builder.MoveTo(frmField.NextSibling.NextSibling);
    builder.InsertHtml(html3);
    // Make the current section Non-Editable
    builder.CurrentSection.ProtectedForForms = true;
    string location = @"c:\";
    doc.Save(location + "TestDoc.docx");
}

If I directly click on “Para3” protection works correctly (it does not let me enter the form field at all). The problem I am having is that when I click onto a Editable form field (para2) and press down arrow I am able to enter the Non-Editable form field (para3) and change its content. Is there something that I need to do to prevent this behavior?
Also, I don’t want all the form fields to be highlighted(shaded gray) except the one’s that do not have protection. Any suggestions?
Thanks.

Hello
Thanks for your request. Let me explain, section protection works only when document protection is turned and only editing in form fields is allowed. By default, all sections are protected, but we can selectively turn protection off using the following line of code:

doc.Sections[0].ProtectedForForms = false;

If you are using AllowOnlyFormFields protection type, and ProtectedForForms is turned on for section, you can edit only FormFields in this section. If ProtectedForForms is turned off you can edit whole section.
Regarding highlighting, you can control it using the following option:
https://reference.aspose.com/words/net/aspose.words/document/shadeformdata/
Best regards,