EditableRange doesn't work for AllowOnlyFormFields

Hi,

I want to have document when first section is editable and second section is protected and contains EditableRange. I read I should use doc.Protect with ProtectionType.AllowOnlyFormFields to have two sections which one is protected and second not. When I create document with ProtectionType.AllowOnlyFormFields I cannot change anything in document in EditableRange.

I run through the following code:

Document doc = new Document();
doc.Protect(ProtectionType.AllowOnlyFormFields, "MyPassword");

DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Paragraph before.");

builder.StartEditableRange();
builder.Writeln("This paragraph is inside an editable range, and can be edited.");
builder.EndEditableRange();

builder.Writeln("Paragraph after.");

doc.Save(@"EditableRange_AllowOnlyFormFields.docx");

Document doc2 = new Document();
doc2.Protect(ProtectionType.ReadOnly, "MyPassword");

DocumentBuilder builder2 = new DocumentBuilder(doc2);
builder2.Writeln("Paragraph before.");

builder2.StartEditableRange();
builder2.Writeln("This paragraph is inside an editable range, and can be edited.");
builder2.EndEditableRange();

builder2.Writeln("Paragraph after.");

doc2.Save(@"EditableRange_ReadOnly.docx");

In document EditableRange_ReadOnly I can change text in editable range but in EditableRange_AllowOnlyFormFields I cannot change editable range.

Could you advise what should I do to use editable range in ProtectionType.AllowOnlyFormFields?
Thanks,
Monika

@acturisaspose To get an editable range in ProtectionType.AllowOnlyFormFields you shall add at least one form.

builder.StartEditableRange();
builder.InsertTextInput("Form", TextFormFieldType.Regular, "", "Initial form text", 0);
builder.EndEditableRange();

It works! Thank you :slight_smile: