We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Set Password For a ReadOnly Region in ASPOSE WORDS

Hi Team,

We have a functionality implemented to set only some part of the documents as editable in WORD File generated using aspose words .NET.

Could you please let us know if we can set a password for the read only region to unlock the document.?

do we have a default;t password for un-protecting the documents generated.?

Aju

@AMS_Support,

Thanks for your inquiry. You can mark whole document as read-only and specify editable regions in Word document. You can meet this requirement after running the following code:

Document doc = new Document();
doc.RemoveAllChildren();

Section section = new Section(doc);
doc.AppendChild(section);

Body body = new Body(doc);
section.AppendChild(body);

Paragraph para = new Paragraph(doc);
body.AppendChild(para);

Run run = new Run(doc);
run.Text = "Hello ";
run.Font.Color = System.Drawing.Color.Red;
para.AppendChild(run);

Run run2 = new Run(doc);
run2.Text = "World!";
para.AppendChild(run2);

doc.Protect(ProtectionType.ReadOnly);

DocumentBuilder builder = new DocumentBuilder(doc);

EditableRangeStart start = builder.StartEditableRange();
EditableRangeEnd end = builder.EndEditableRange();

run2.ParentNode.InsertBefore(start, run2);
run2.ParentNode.InsertAfter(end, run2);

doc.Save("D:\\temp\\18.7.docx");