I'm trying to open an URL following a simple method written all over google and even MSDN. But for unknown reasons I get an Exception as follows:
Win32Exception was unhandled
Message: Application not found
Here's my code:
private void linkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)开发者_开发技巧
{
ProcessStartInfo sInfo = new ProcessStartInfo("http://github.com/tbergeron/todoTxt");
Process.Start(sInfo);
}
Any idea why it is failing?
Thanks a lot!
I had a similar issue trying this with .NET Core and getting a Win32Exception
, I dealt with it like so:
var ps = new ProcessStartInfo("http://myurl")
{
UseShellExecute = true,
Verb = "open"
};
Process.Start(ps);
This is apparently machine-specific behaviour (http://devtoolshed.com/content/launch-url-default-browser-using-c).
The linked article suggests using Process.Start("http://myurl")
but catching Win32Exception
and
falling back to Process.Start("IExplore.exe", "http://myurl")
:
try
{
Process.Start("http://myurl");
}
catch (Win32Exception)
{
Process.Start("IExplore.exe", "http://myurl");
}
Sadly after trying almost everything, this was the best I could do on my machine.
You are looking for the string
overload of Process.Start()
:
Process.Start("http://github.com/tbergeron/todoTxt");
Throw start in front of it, if you want to launch in the default browser:
new ProcessStartInfo("start http://github.com/tbergeron/todoTxt");
精彩评论