0

I wanted to open link from my c# application. I saw many people writing this code:

System.Diagnostics.Process.Start("https://www.example.com");

but everything this code does for me is just stopping the program and displays error that says the system can't find this file.

Please help me :(

Martin
  • 16,093
  • 1
  • 29
  • 48
lupus
  • 9
  • 2

1 Answers1

1

This is because by default, the process is started with UseShellExecute set to false, which means that the process can only run executable files (such as .exe files).

Instead, specific UseShellExecute = true to allow the OS to determine how to launch the process, as per the following example:

Process newProcess = new Process();
newProcess.StartInfo.FileName = "https://www.example.com";
newProcess.StartInfo.UseShellExecute = true;
newProcess.Start();

The docs for UseShellExecute state:

Gets or sets a value indicating whether to use the operating system shell to start the process.

In this case, you do want that.

Martin
  • 16,093
  • 1
  • 29
  • 48