Reputation:
WinForms App / RSS News Feed Control
What I want to achieve is:
If user wants to open an URL from RSS news feed of the winApp, then
So, generally 1-st and 3-rd are the points of my interest to ask you.
Upvotes: 1
Views: 4422
Reputation: 6103
System.Diagnostics.Process.Start(startUrl);
thats all. It checks if default browser is open, run it if not and open the url in new tab and activates it.
Upvotes: 2
Reputation: 376
is there a reason you need to do the first 2 parts? Why do you care what is the default browser? Will you change what you do?
What what are you sending the URL to shell for?
If using .NET, and when using Process class - when passing it a link, it will use the default browser. So the same application may launch Chrome or IE respectively.
There is another stack that shows how to do this already: Open a URL from Windows Forms
ProcessStartInfo sInfo = new ProcessStartInfo("http://example.com/");
Process.Start(sInfo);
Upvotes: 1
Reputation: 17213
This is obviously going to vary by browser, but its clear you've done almost no research on this so I'll be your research assistance.
Generally you can just execute the URL on the path, and the default browser will open a new tab or start as nessesary. there shouldn't be any need to do the following. execute explorer.exe "http://google.com"
in your CMD window to see how this works with various default browsers.
I googled "How to detect the default browser C#"
which yielded several results, the first of which is How to find default web browser using C#? - this has a couple answers, the second one seems to be the one that you want.
Once you know the default browser, you need to check if it's open. So you will need to compile a list of binary names for each browser (chrome is chrome.exe
) and we search for "check if process is running C#"
and that gives us How can I know if a process is running?
Now, we know if the browser is running. If it is we will have a Process
instance - so we need to now know the binary location (this is important!). So we search for Get the path of a running process C#
and that gives us C#: How to get the full path of running process?
Each browser will have it's own mechanism for opening a new tab and receiving focus, but generally you need to execute the binary with some arguments. For Google Chrome, the answer is here: https://superuser.com/questions/731467/command-line-option-to-open-chrome-in-new-window-and-move-focus
So now we have completed everything for the google chrome browser. Repeat for other browsers, and do similar research to find out how to execute the binary to open a new tab.
If you want a generic solution that works for all browsers, this already exists. just execute explorer "yourUrl"
.
Upvotes: 0