0
votes

When a Word document is opened in my Word Add-in, I validate the document. The validation requires the document to be saved so I call the save method:

Microsoft.Office.Tools.Word.Document.Save()

If the document is read-only, (my use case is opening an attached document from Outlook), the Save As dialog opens. If I save the document or hit cancel, a COMException is thrown for both cases with the message "This file is read-only. (File name.)".

Typically, a user cancellation COMException is thrown for Cancel and I would expect no exception to be thrown if the file is saved correctly. Is this a bug or do I need to handle the file differently?

1

1 Answers

1
votes

There are two things you could do to avoid described behaviour (at least works great for me). First, you should use save as -functionality for it: document.SaveAs("/MyDocuments/example.doc"). You can also "force" application to save the document without any dialogs and you can achieve this by useing Document.Application.DiplayAlerts = False. Then you just enable the alerts after saving.

Hopefully this will help you.