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  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to