-3

I try to open a PDF file with whatever the user has setup on his computer for PDFs.

I found this on Stackoverflow:

        System.Diagnostics.Process.Start(helpPath);

Or

        ProcessStartInfo startInfo = new ProcessStartInfo(helpPath);
        Process.Start(startInfo);

Both will give me the same message:

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

Trevor
  • 7,777
  • 6
  • 31
  • 50
PassionateDeveloper
  • 14,558
  • 34
  • 107
  • 176
  • Have you tried [using the cmd.exe as your Process](https://stackoverflow.com/questions/46808315/net-core-2-0-process-start-throws-the-specified-executable-is-not-a-valid-appl), with `helpPath` as the argument, instead of using the `helpPath` directly as the Process? – Tam Bui May 17 '21 at 16:51
  • Are you possible using `.net.core`? What target platform are you targeting? Anyways, try setting the [UseShellExecute](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.useshellexecute?view=net-5.0) property (The default is true on .NET Framework apps and false on .NET Core apps): `startInfo.UseShellExecute= true;` – Trevor May 17 '21 at 16:56
  • Yes, itrs .net core 5- – PassionateDeveloper May 17 '21 at 17:01
  • It think there is a problem with the application associated with pdf document on your computer. The [documentation](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.start?view=net-5.0#System_Diagnostics_Process_Start_System_String_) says this exception cause is : *An error occurred when opening the associated file. -or- The file specified in the fileName could not be found* – XouDo May 20 '21 at 04:48

1 Answers1

1

You can open pdf in default web browser.

Use:

Process.Start("explorer", helpPath);

For Internet Explorer:

Process.Start("C:\Program Files\Internet Explorer\iexplore.exe", helpPath);