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

Free Support Forum - aspose.com

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.

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


Document doc = new Document(MyDir + “Source.rtf”);<o:p></o:p>

OoxmlSaveOptions opt = new OoxmlSaveOptions(SaveFormat.Docx);<o:p></o:p>

opt.Compliance = OoxmlCompliance.Iso29500_2008_Transitional;<o:p></o:p>

opt.Password = “password”;<o:p></o:p>

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.