Search code examples
c#windows-8query-string

Opening a URL containing a query string


I need to be able to open a link in a browser from a C# application. Normally, I would use a code like this to open the link:

Process.Start(new ProcessStartInfo("explorer.exe", @"http://www.google.com"));

Unfortunately, that only succeeds in opening explorer and not a browser when the URL contains a query string such as: http://www.google.com/search?q=stackoverflow

How can I open URLs with query strings?

Edit Notes: I am using Windows 8 with non-IE default browsers. I am seeing the same error with 'Class Not Registered' when trying to use just Process.Start as described here: Process.Start(url) broken on Windows 8/Chrome - are there alternatives?


Solution

  • Finally found a solution -- kind of impressed I didn't try this to begin with after writing batch files years ago this was common.

    Process.Start(new ProcessStartInfo("explorer.exe", "\"" + @"http://www.google.com/search?q=stackoverflow" + "\""));
    

    Just adding quotes around it seems to work fine.