C# .NET 6 - How to open a link in default browser? [duplicate]
Asked Answered
D

1

7

I want to open a website with the default browser. In .NET Framework I always used Process.Start("https://google.com") but when I do this in .NET 6, I get an exception saying that the File was not found:

System.ComponentModel.Win32Exception: 'An error occurred trying to start process 'https://google.com' with working directory 'C:\C#Projects\TestForm\MyFormsApp\bin\x64\Debug\net6.0-windows'. Das System kann die angegebene Datei nicht finden.'

Do I need to manually determine the default browser to make this work with URLs?

Edit: I don't understand why this question got marked as duplicate, the other question is from 2014, its marked answer is not that helpful, and the question is not specific to my situation of something which worked in .NET Framework but not in .NET 6. Also it's not specifically about using the default browser.

Dullish answered 23/4, 2022 at 7:55 Comment(1)
You should please read this: https://mcmap.net/q/332940/-process-start-url-failsSalver
T
12

Pass the url to the ProcessStartInfo argument to the Process.Start method. See this example.

Tshombe answered 23/4, 2022 at 8:0 Comment(1)
Need to make sure UseShellExecute = trueTercet

© 2022 - 2024 — McMap. All rights reserved.