Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process.Start to open an URL, getting an Exception?

Tags:

c#

.net

winforms

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

Exception

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!

like image 696
Tommy B. Avatar asked Oct 07 '11 22:10

Tommy B.


People also ask

What does process Start do?

Start(ProcessStartInfo)Starts the process resource that is specified by the parameter containing process start information (for example, the file name of the process to start) and associates the resource with a new Process component.

What is process start in C#?

Start(String) Starts a process resource by specifying the name of a document or application file and associates the resource with a new Process component. public: static System::Diagnostics::Process ^ Start(System::String ^ fileName); C# Copy.

How do I start a process in VB net?

Start another application using your . NET code As a . NET method, Start has a series of overloads, which are different sets of parameters that determine exactly what the method does. The overloads let you specify just about any set of parameters that you might want to pass to another process when it starts.


2 Answers

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);
like image 151
Flatliner DOA Avatar answered Sep 21 '22 08:09

Flatliner DOA


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.

like image 31
Nicholas Blumhardt Avatar answered Sep 22 '22 08:09

Nicholas Blumhardt