0

I want to open a PDF with the default windows behaviour the user has saved (e.g. internet explorer, adobe, whatever).

I found this solution Opening a .pdf file in windows form through a button click

and implemented it here:

        ProcessStartInfo startInfo = new ProcessStartInfo("MyPdfPath");
        Process.Start(startInfo);

Sadly I got an Error:

   System.ComponentModel.Win32Exception: "The specified executable is not a valid application for this OS platform."

I tried to google this error, but nothing of the first ten solution ideas worked.

PassionateDeveloper
  • 14,558
  • 34
  • 107
  • 176

1 Answers1

1

The system is treating it like an executable, one way to get the document behavior is to set UseShellExecute to true:

ProcessStartInfo startInfo = new ProcessStartInfo("MyPdfPath");
startInfo.UseShellExecute = true;
Process.Start(startInfo);
  • Or see https://stackoverflow.com/questions/46808315/net-core-2-0-process-start-throws-the-specified-executable-is-not-a-valid-appl/47066203#47066203 the link to which appears in the linked question. –  Apr 23 '21 at 12:28