views:

612

answers:

5

Hey,

I know there is built-in Internet explorer, but what I'm looking for is to open Firefox/Mozilla window (run the application) with specified URL. Anyone can tell me how to do that in C# (.nET) ?

A: 

Use the Process class (System.Diagnostics) using the URL as the process name. This will use the system default browser to open the URL. If you specify a browser, you run the risk that the browser doesn't exist.

Austin Salonen
A: 

See ProcessInfo.UseShellExecute

Ilya Ryzhenkov
A: 

In Visual Studio click the File -> Browse With... on the menus and then select the browser that you want to use. You can also change the browser there. If the Browse With... menu option doesn't appear then you need to select a project from your solution that that can be launched in a browser.

Guy
A: 

If you explicitly do not want to use the User's default browser, you can run the browser with the URL as the first argument.

C:\Program Files\Mozilla Firefox>firefox.exe http://google.com

launches Firefox with google for me. But as people have said, you run the risk of it not being installed, or being installed to a different place, etc.

Tom Ritter
wrt installation location, you can check the registry under HKLM\SOFTWARE\Mozilla
Blorgbeard
+3  A: 

This will launch the system defined default browser:

string url = "http://stackoverflow.com/";
System.Diagnostics.Process.Start(url);

Remember that Process.Start(url) might throw exceptions if the browser is not configured correctly. (Thanks Vegard)

Hallgrim
Note that this might fail if there is something wrong with the browser configuration. Make sure you catch the appropriate exceptions. I've just had this reported to me using automated crash reports, no good way to solve it except catching the correct exceptions.
Vegard Larsen