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

Free Support Forum - aspose.com

Document Password


I would like to know how I can set a password for a document so that the document can’t be opened without the password.


Hi Devid,

Thanks for your inquiry. Please use the following code snippet for your requirement and read following documentation links for your kind reference.


Document doc = new Document();<o:p></o:p>

DocSaveOptions options = new DocSaveOptions(SaveFormat.Doc);<o:p></o:p>

options.Password = “test”;

doc.Protect(ProtectionType.ReadOnly, “passoword”);


doc.Save(MyDir + “AsposeOut.doc”, options);

Document doc = new Document();

OoxmlSaveOptions options = new OoxmlSaveOptions(SaveFormat.Docx);

options.Password = "test";

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

doc.Save(MyDir + "AsposeOut.docx", options);

Please let us know if you have any more queries.

Hi tahir.manzoor,

Thanks a lot for your help, I solved my problem by using the code you suggested.


Hi Devid,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.