Word password protection

Hi,

I’m trying to implement a method for saving a document with a password.
I don’t want to let the end user to open the document as readonly.

I’ve found that I can do:

DocSaveOptions SaveOpt = new DocSaveOptions();
SaveOpt.Password="MyPassword";
Document.Save(OutputPath, SaveOpt);

So, I thing this is the right way to do it for “doc” documents.
What about the “docx” and “docm” file? Is there any way to do that?

Thanks,
Devid

Hi Devid,

Thanks for your inquiry. OoxmlSaveOptions** can be used to specify additional options when saving a document into the Docx, Docm, Dotx, Dotm or FlatOpc format. Please use the following code snippet for your requirement and read following documentation links for your kind reference.

https://reference.aspose.com/words/net/aspose.words.saving/docsaveoptions
https://reference.aspose.com/words/net/aspose.words.saving/ooxmlsaveoptions

Document doc = new Document(MyDir + "Source.rtf");
OoxmlSaveOptions opt = new OoxmlSaveOptions(SaveFormat.Docx);
opt.Compliance = OoxmlCompliance.Iso29500_2008_Transitional;
opt.Password = "password";
doc.Save(MyDir + "AsposeOut.docx", opt);

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