Free Support Forum - aspose.com

How to set opening password, modifying password and editing password respectively?


#1

Hi, Support,

I have the question how to set password for opening , modifying or editing a document respectively. how to work it out?
By using SaveOption method, it seems only to set opening password for document?

Thanks for your help!

Ducaisoft


#2

@ducaisoft,

You can use the following overload of Protect method:

Document doc = new Document("E:\\temp\\input.docx");
doc.Protect(ProtectionType.ReadOnly, "password");
doc.Save("E:\\temp\\19.2.docx");

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

Document doc = new Document("E:\\Temp\\input.docx");

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

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

Hope, this helps.