3

I am trying to open an html file from c#. I am on Mac I tried

Process.Start(path);

but it gave me "permission denied" I have copy and pasted the exact path into both google and finder and they both gave me the correct file. I am running this from an administrator account. I have tried moving the path to different places, like Desktop, and it gives the same error.

Then I tried:

new ProcessStartInfo(
            path,
            "--no-first-run")
        { UseShellExecute = false });

I get the same error. What is wrong? Just for kicks, I tried changing the path to be wrong, and it says "wrong path", so I know that the path is right.

Thank you for any help or extra info you can provide.

  • You can not "execute" an HTML, use "open yourHTMLfile". (`The open command opens a file (or a directory or URL), just as if you had double- clicked the file's icon. If no application name is specified, the default application as determined via LaunchServices is used to open the specified files.`) – SushiHangover Apr 25 '20 at 16:46
  • @SushiHangover, but [this answer](https://stackoverflow.com/a/811543/1563833) says that you can, indeed, just use `Process.Start(path)`, and it's even specified in the docs as such. So what's up with that? – Wyck Apr 25 '20 at 16:51
  • 1
    Set `UseShellExecute = true` and try again, as Finder uses the shell to open the HTML page. – Lex Li Apr 25 '20 at 17:01
  • @Wyck Jon answered a specific question, which only applies to Windows and .NET Framework. You cannot assume it applies to Mac and Mono, as the default value for things like `UseShellExecute` can be different. – Lex Li Apr 25 '20 at 17:03
  • @LexLi, thanks, of course, somehow that didn't register for me when I read this. It seems that "I am on Mac" and the "mono" tag should have been bold and blinking to for me. – Wyck Apr 25 '20 at 17:08
  • @Wyck `/usr/bin/open` is an macOS provided executable and you can avoid any OS issues by calling `open` and passing in your URL as the parameter. FYI: Finder does not use the "shell" to open file associations – SushiHangover Apr 25 '20 at 17:45
  • @LexLi It worked! thank you so much – William Ehrenberg Apr 25 '20 at 18:11

1 Answers1

1

using UseShellExecute = true fixed the issue for me (at least on mac) Thanks to @LexLi