tags:

views:

178

answers:

1

I have my program written in C#. It has label link. I need to define programmatically, when I click this link (programmatically too), if default browser opens the needed page. C#

+2  A: 
Process.Start("http://example.com"); // <-- put your url there.

Also see this short article on how to use that to greatest effect:
http://code.logos.com/blog/2008/01/using_processstart_to_link_to.html

In summary:

void OpenBrowser(string url)
{
    try
    {
        Mouse.OverrideCursor = Cursors.AppStarting;
        Process.Start(url);
    }
    catch (Exception)
    { //swallow: exception is sometimes thrown even though
    } // the call completed without error
    finally
    {
        Mouse.OverrideCursor = null;
    }
}
Joel Coehoorn
Hmmmm, it seems to me you try to open browser. I need something different. I can open browser, but I need to define programmatically IF the needed page was open or not.
Seacat
Then just return true: if you passed a valid url and the internet is available, you can assume the call succeeded.
Joel Coehoorn
But if you want to _really_ be sure, Process.Start() returns a Process instance you can then use to try to determine what page was loaded if any.
Joel Coehoorn
And, it goes without saying, you would *do* something in that empty catch block so that you're not blindly hiding all exceptions. ;) To the asker: It seems like you're concerned that *your* page would not be loaded when you start the process, is that correct? Why would it not do so?
JMD
No, you would just blindly catch here. Read the link- the exception is thrown erroneously.
Joel Coehoorn
Updated code sample to make that clearer.
Joel Coehoorn
NO, I just want to test my program - if it opens browser and if the browser opens the needed page
Seacat