[Mono-list] Opening user's browser
Aaron Bockover
abockover at novell.com
Thu Dec 22 18:37:48 EST 2005
If using Gtk# with Gnome support:
Gnome.Url.Show(...)
--Aaron
On Thu, 2005-12-22 at 12:59 -0200, Felipe Almeida Lessa wrote:
> Hi,
>
> I'd like to have a function that opens a link in the user's web
> browser. Googling about it I didn't find an arch-independent solution.
> The best I could do until now is:
>
> public static bool OpenLink(string address) {
> try {
> int plat = (int) Environment.OSVersion.Platform;
> System.Diagnostics.Process proc;
> if ((plat != 4) && (plat != 128)) {
> // Use Microsoft's way of opening sites
> proc = System.Diagnostics.Process.Start(address);
> } else {
> // We're on Unix, try several browsers
> string cmdline = String.Format("firefox {0} || mozilla-firefox {0}" +
> " || epiphany {0} || galeon {0} || opera {0} || dillo {0}", address);
> proc = System.Diagnostics.Process.Start(cmdline);
> // Sometimes we need to wait for bash
> System.Threading.Thread.Sleep(500);
> }
> return (!proc.HasExited || proc.ExitCode == 0);
> } catch {
> return false;
> }
> }
>
> I'd like to know what you think about it, and if there's a better
> solution. Also, I think that a snippet of code showing how to do this
> should be put on mono-project.com, as this may help other people too.
>
> Cya,
> Felipe.
> _______________________________________________
> Mono-list maillist - Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
More information about the Mono-list
mailing list