views:

389

answers:

3

I need to open an url from my application, on both linux and windows and i want to avoid replacing an existing page on an open browser.

How do i call for it to open?

I know i can use

System.Diagnostics.Process.Start("http://mysite.com");

which should also work under linux, but this will replace any page shown on an already open browser window.

i found this article ( thx to Nissan Fan):

System.Diagnostics.Process.Start("http://mysite.com");

but this only works for windows and i need a solution that will work on both systems.

A: 

i would suggest to check on what OS the app is running, and then implement it for each OS separately.

andremo
A: 

After searching through the Banshee source code I see that they use Gnome.Url.Show() (In gnome-sharp) to open the users default browser.

If that isn't possible for whatever reason, a couple of other ideas come to mind.

If the user is running Gnome there should be a program called "gnome-open" that should do the trick.

System.Diagnostics.Process.Start("gnome-open http://mysite.com");

And if that doesn't work I know that (at least) all Debian-based systems come with a script called sensible-browser.

System.Diagnostics.Process.Start("sensible-browser http://mysite.com");
wm_eddie
I also discovered xdg-open which looks like a cross-desktop gnome-open.
wm_eddie
Note that Process.Start takes arguments separately to the executable name/path: Process.Start ("xdg-open", "http://example.com"). Also, note that using xdg-open explicitly is pretty redundant because Process.Start (""http://example.com") uses "xdg-open" on Linux (with some fallbacks), "open" on MacOS, and shellexec on Windows.
mhutch
+1  A: 

I think this is what you want:

System.Diagnostics.Process.Start ("xdg-open http://mysite.com");

This will only work on linux, but should work for all linux desktops. Like grombeestje said, you should probably implement it separately for Windows and linux.

Matthew