1

i'm new in C# programming so I beg your pardon. I just tried the solution proposed in a previous question, but it didn't work. By the way I stil need help. I'm trying to write a simple consolle app in C# that opens a web page, aka http://www.libero.it. Here you are my code:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; class OpenWeb { static void Main(string[] args) { var prs = new ProcessStartInfo("chrome.exe"); prs.Arguments = "http://www.libero.it"; // Process.Start(prs); try { Process.Start(prs); } catch (System.ComponentModel.Win32Exception ex) { Console.WriteLine(ex.Message); } } } 

I don't understand why my code doesn't work, there is always an exeception, without the try-catch is the following:

Unhandled Exception: System.ComponentModel.Win32Exception: The specified file could not be found at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at OpenWeb.Main(String[] args) in C:\Users\p3rtp\myProve\Prove.cs:line 12 

I use Windows 7x64, with .Net core sdk 2.1.301 e MS Visual Studio Code 1.24.1.

6
  • 2
    chrome.exe is not in PATH - or even, it might not be installed. Commented Jul 9, 2018 at 13:37
  • Do you have chrome.exe in your path, i.e. would you expect this program to find it from just chrome.exe? You could pass the URL to the shell instead so that it will use its configured browser, and it would know the path to that. Commented Jul 9, 2018 at 13:37
  • 2
    Possible duplicate of How to open a web page from my application? Commented Jul 9, 2018 at 13:38
  • 2
    you need to define the absolute path of Chrome.exe for example "C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe" Commented Jul 9, 2018 at 13:38
  • 1
    chrome.exe is very unlikely to be in the same folder as your .NET application. If you don't specify a folder, .NET will look for this file in the folder where it's running, and in the Windows PATH variable for the current user. So unless chrome.exe is also in the user's PATH variable, then this will fail. Either add it to PATH or use the full folder name as well. Also there's no guarantee Chrome will be installed on a user's machine - maybe you need a fallback mechanism to make it run I.E. instead if Chrome can't be found. Commented Jul 9, 2018 at 13:57

3 Answers 3

4

I've been using this line to launch the default browser:

System.Diagnostics.Process.Start("http://www.google.com"); 
Sign up to request clarification or add additional context in comments.

Comments

1

The code is really simple as below:

using System using System.Collections.Generic using System.Text using System.Diagnostics namespace example { class examp { static void Main(string[] args) { Process.Start("http://www.google.com"); } } } 

1 Comment

I believe you are missing certain dlls.
1

Ok, I found the right answer:

var prs = new ProcessStartInfo(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"); 

The problem isn't the Path, but in the app or folder: just the quotes with "@" before the full path of chrome I finally managed to solve the problem. Thanks to all anyway.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.