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
2009-02-02 21:41:51
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
2009-02-02 21:47:43
Then just return true: if you passed a valid url and the internet is available, you can assume the call succeeded.
Joel Coehoorn
2009-02-02 21:48:49
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
2009-02-02 21:51:15
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
2009-02-02 21:53:52
No, you would just blindly catch here. Read the link- the exception is thrown erroneously.
Joel Coehoorn
2009-02-02 21:55:26
Updated code sample to make that clearer.
Joel Coehoorn
2009-02-02 22:13:11
NO, I just want to test my program - if it opens browser and if the browser opens the needed page
Seacat
2009-02-02 22:54:42