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

Free Support Forum - aspose.com

Adding restrictions and password back into document

We have a program that takes a bunch of documents from the database. We strip some stuff off of them and merge them into one document.

Issue is the stripped stuff is the formatting restrictions and password that is put on buy the user.

Can aspose add the document restrictions which would be-
Formatting Restrictions:
Caption Text
In Text Table Text
In Text Table Text Right Align
Mandatory Budget Table

Block theme or scheme switching
Block Quick Style Set Switching

Then let us put a password back on? Any help would be appreciated.



Thanks for your inquiry. You can mark whole document as read-only and specify editable regions in Word document. I think, you can meet this requirement after running the following code: (see Protecting Documents)

Document doc = new Document();

Section section = new Section(doc);

Body body = new Body(doc);

Paragraph para = new Paragraph(doc);

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

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


DocumentBuilder builder = new DocumentBuilder(doc);

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

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


thank you for your reply.

I’m trying to restrict them from modifying specific styles.

Also how do you set a password on the code you gave me in case they want to unprotect it?


To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your simplified input Word document
  • Your expected document which shows the correct output. Please create this document by using Microsoft Word application.
  • Please also list the complete steps that you performed in MS Word to get the desired output.

As soon as you get these pieces of information ready, we will start further investigation into your scenario and provide you code to achieve the same by using Aspose.Words. Thanks for your cooperation.

You can use the following overload of Protect method:

doc.Protect(ProtectionType.ReadOnly, "password");

Also, in order to save document with encryption please use the following code snippet:

Document doc = new Document("D:\\Temp\\in.docx");

OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
saveOptions.Password = "myPassword";

doc.Save("D:\\Temp\\out.docx", saveOptions);