Free Support Forum - aspose.com

Document Password

Hi,


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.

regards,
Devid.

Hi Devid,


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

http://www.aspose.com/docs/display/wordsnet/DocSaveOptions+Class
http://www.aspose.com/docs/display/wordsnet/OoxmlSaveOptions+Class

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”);

<o:p></o:p>

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.

Regards,
Devid

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.