ArgumentException when setting SaveFormat

I feel certain this is a case of pilot error, but I’ve been unable to find the solution in either the documentation or the forum.
I am using Aspose.Words v 13.1.0.
I need to save an RTF file as a .DOC or .DOCX file (sometimes one, sometimes the other).
I sometimes need to password-protect the output.
If I assign a DocSaveOptions object to the document.Save method when saving as a DOC file, everything works properly.
If I assign a DocSaveOptions object when saving as a DOCX file, I get an ArgumentException with a message of “An invalid SaveFormat for this options type was chosen.”.
The DocSaveOptions object is the only way I know of to assign a password. What’s the proper way to address this issue with the DOCX format?
An example program is attached.
Thanks.
Jim McFadden/Unum, Chattanooga, TN

Hi Jim,

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.