Reputation: 2960
Is there a way I can launch a tab (not a new Window) in Google Chrome with a specific URL loaded into it from a custom app? My application is coded in C# (.NET 4 Full).
I'm performing some actions via SOAP from C# and once successfully completed, I want the user to be presented with the end results via the browser.
This whole setup is for our internal network and not for public consumption - hence, I can afford to target a specific browser only. I am targetting Chrome only, for various reasons.
Upvotes: 51
Views: 144668
Reputation:
// open in default browser
Process.Start("http://www.stackoverflow.net");
// open in Internet Explorer
Process.Start("iexplore", @"http://www.stackoverflow.net/");
// open in Firefox
Process.Start("firefox", @"http://www.stackoverflow.net/");
// open in Google Chrome
Process.Start("chrome", @"http://www.stackoverflow.net/");
For .Net core 3.0 I had to use
Process process = new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.FileName = "chrome";
process.StartInfo.Arguments = @"http://www.stackoverflow.net/";
process.Start();
Upvotes: 48
Reputation: 2323
As a simplification to chrfin's response, since Chrome should be on the run path if installed, you could just call:
Process.Start("chrome.exe", "http://www.YourUrl.com");
This seem to work as expected for me, opening a new tab if Chrome is already open.
Upvotes: 69
Reputation: 131
If the user doesn't have Chrome, it will throw an exception like this:
//chrome.exe http://xxx.xxx.xxx --incognito
//chrome.exe http://xxx.xxx.xxx -incognito
//chrome.exe --incognito http://xxx.xxx.xxx
//chrome.exe -incognito http://xxx.xxx.xxx
private static void Chrome(string link)
{
string url = "";
if (!string.IsNullOrEmpty(link)) //if empty just run the browser
{
if (link.Contains('.')) //check if it's an url or a google search
{
url = link;
}
else
{
url = "https://www.google.com/search?q=" + link.Replace(" ", "+");
}
}
try
{
Process.Start("chrome.exe", url + " --incognito");
}
catch (System.ComponentModel.Win32Exception e)
{
MessageBox.Show("Unable to find Google Chrome...",
"chrome.exe not found!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Upvotes: 6
Reputation: 23113
UPDATE: Please see Dylan's or d.c's anwer for a little easier (and more stable) solution, which does not rely on Chrome beeing installed in LocalAppData
!
Even if I agree with Daniel Hilgarth to open a new tab in chrome you just need to execute chrome.exe with your URL as the argument:
Process.Start(@"%AppData%\..\Local\Google\Chrome\Application\chrome.exe",
"http:\\www.YourUrl.com");
Upvotes: 25