2

I am using the Word Interop and wish to open a .pdf file and let word automatically do the conversion.

I have the following properties set.

var wordApp = new Word.Application();
wordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
wordApp.Options.DoNotPromptForConvert = true;
wordApp.Options.ConfirmConversions = false;
var doc = wordApp.Documents.OpenNoRepairDialog(ExternalFilePath, false, true);

However when it does the Open I still get the following prompt:

enter image description here

Word version 2016.

Does anyone know how to by-pass this? If I click OK the rest of the program executes as I'd expect successfully.

I am aware of and do not wish to use any other third-party tools.


Thanks to BugFinder for the suggestion of using the Format parameter, but still no luck with this.

Here are the additions to the code:

Word.FileConverters converters = wordApp.FileConverters;
var wordPdfConverter = converters.OfType<Word.FileConverter>().Where(c => c.CanOpen == true && c.Extensions == "pdf").First();
var doc = wordApp.Documents.OpenNoRepairDialog(ExternalFilePath, false, true, false, Format: wordPdfConverter.OpenFormat, NoEncodingDialog: true);

This gets a converter but still displays the prompt. :(


Further edit thanks to Cidney's comments. It appear this prompt is a user registry setting as that to bypass it in the interop is impossible. Seems a like a flaw with the Interop to me. The Open XML SDK does not support saving as XPS so this is unavailable too. Appears I will have to manipulate the users registry first to achieve this (brings write permission concerns) or check if Word is waiting for user input and send keys.

Ryan Thomas
  • 1,724
  • 2
  • 14
  • 27
  • other than try supplying the converter (which is one of the later parameters) .... – BugFinder Oct 17 '19 at 14:49
  • @BugFinder Thanks, I have explored this route and updated the question. – Ryan Thomas Oct 17 '19 at 15:08
  • See the checkmark in the lower, left-hand corner: `Don't show this message again`? This writes to the Registry. See the end of the "Answer" in this question to get the Registry entry that needs to be changed and what the settings are: https://stackoverflow.com/a/46026428 – Cindy Meister Oct 17 '19 at 19:13
  • Thank you @Cindy Meister - this seems like a big Microsoft flaw with the Interop to me. What if the user running my application does not have permission to write to the registry? Thank you for the post though, is very helpful. :) – Ryan Thomas Oct 18 '19 at 08:20
  • That‘s why MS expressly points out that the Office applications are **end-user** liscensed; devs are „guests“ and need to „expect“ messages requiring user interaction... One reason the Open XML file formats were developed... One workaround is to test whether Word is waitimg and use SendKeys to confirm a message... – Cindy Meister Oct 18 '19 at 10:18
  • Except the Open XML SDK does not support converting to XPS :( Your proposal around checking if Word is waiting and SendKeys could be interesting, however I think I may park this implementation for now. Thanks for the suggestions. – Ryan Thomas Oct 18 '19 at 10:47

0 Answers0