Morta
Morta

Reputation: 224

Can't open link in c#

If I try to use:

System.Diagnostics.Process.Start("http://google.com");

the following error occurs:

System.ComponentModel.Win32Exception: "The system cannot find the file specified"

I use win10 and visual studio.

Actually I can't find a solution or something like that. Maybe it's because i'm behind a proxy ? Or could there be any other problem ? And if yes, could you help me to fix it ?

Upvotes: 4

Views: 2557

Answers (2)

Leo
Leo

Reputation: 14820

I think I should document this here since I haven't seen many answers explaining why that error happens

The actual problem you are facing is that you are using the incorrect overload. The only parameter accepted by this overload is a file or document name. According to MSDN, URLs are NOT consider documents.

You find that statement hidden in one of the examples in the documentation here...

https://msdn.microsoft.com/en-us/library/53ezey2s(v=vs.110).aspx

enter image description here

Now, the correct overload is...

System.Diagnostics.Process.Start(string fileName, string arguments);

where filename is name of the process you want to start (IE, Chrome, etc.) and arguments in this case would be the URL to pass to the process. More infor here...

https://msdn.microsoft.com/en-us/library/h6ak8zt5(v=vs.110).aspx

Upvotes: 1

SpiderCode
SpiderCode

Reputation: 10122

Can you try below work around:

System.Diagnostics.Process.Start("cmd","/c start http://www.google.com");

Upvotes: 12

Related Questions