3

i'm using the following code to open site in internet explorer

ProcessStartInfo startInfo = new ProcessStartInfo
{
  Arguments = "http://www.example.com",
  FileName = "C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe",
  RedirectStandardInput = true,
  UseShellExecute = false
};
System.Diagnostics.Process process = System.Diagnostics.Process.Start(startInfo);

How can i open my site in a new tab not a new browser considering that there is a browser already opened???

Well,

We are Building an application where the user can use 2 options:

1-Using the default browser.

2- use one of the following browsers: IE,Google Chrome and Firefox (for now).

and after choosing which browser want to use in his application, he must choose if he want to open the requested page in a new window or in a new tab.

for example: if he choose IE with new tab option, so the system will try to find the last page opened by the program and refresh it if exist, and if not he will open it in a new tab.

Concerning the IE browser i think that EricLaw -MSFT helped me to found a way to open a new tab and a new window, i still have to know how can i get an opened tab (already opened by my program) and refresh in need.

I still have to do the same for Firefox and Google Chrome.

Thanks for your answers, and sorry again for my bad english :)

Gokul
  • 788
  • 2
  • 12
  • 30
Gaby
  • 2,923
  • 4
  • 38
  • 52

3 Answers3

8

You can simply use:

Process.Start("http://www.mysite.com");

This will not necessarily open in IE, but in the users default browser as a new tab (if the browser supports it) and that is probably what the user wants anyway ;)

Øyvind Bråthen
  • 59,338
  • 27
  • 124
  • 151
  • 1
    +1 Opening in the user's default browser is highly recommended. As a power user I get highly annoyed when an application tries to launch IE for a site when I can launch Chrome in 1/2 the time and IMHO have a better browsing experience. – scunliffe Oct 01 '10 at 11:48
  • you're write, your solution works fine but what if the user doesn't want to use his default browser? how can i do it? – Gaby Oct 01 '10 at 12:08
  • As far as I know you can't, if not, as Fiona Holder wrote, IE has some command line parameter you can pass to it to give this functionality. And I doubt it, since that means that the instance of IE your trying to open has to see if another instance if open, send the URL to that instance and close itself. – Øyvind Bråthen Oct 01 '10 at 12:26
  • 1
    If you want to guarantee that you launch a new tab in an existing IE instance, you cannot do so by ShellExec'ing from the command line. You probably could do it by using the Navigate2 API with appropriate flags after having found an existing window in the ShellWindows collection. Because of the integrity level challenge, this would not be simple. – EricLaw Oct 03 '10 at 20:18
  • Thanks EricLaw -MSFT, it is working i only have to give the navigate2(myUrl,2048,...), 2048 to open new tab.PLease posted as an answer to mark it as write answer :) Btw now i want to make same work with fireFox and GoogleChrome, do you have any ideas?? – Gaby Oct 04 '10 at 07:53
  • If you want to do this per browser, I really don't understand the reasoning. I thought that you maybe had some IE specific functionality and therefore needed to open it in IE only. But if it's supposed to work for many browsers, why not just take the default browser for the user? This promise this will annoy a shitload of users :) – Øyvind Bråthen Oct 04 '10 at 08:02
  • Hi Øyvind Bråthen, Sorry man i think that it is my fault because i'm not good in english and i can't explain exactly what i need, but i'll try. Please look to my edited question :) – Gaby Oct 05 '10 at 06:00
2

reference Interop.SHDocVw.dll

 InternetExplorer ie = null;

 SHDocVw.ShellWindows allBrowser = new SHDocVw.ShellWindows();//gives all browsers
 int browserCount = allBrowser.Count - 1;//no . of browsers
 while (browserCount >= 0)
   {
     ie = allBrowser.Item(browserCount) as InternetExplorer;
     if (ie != null && ie.FullName.ToLower().Contains("iexplore.exe"))//all IE will have this name
       {
         ie.Navigate2("http://www.example.com", 0x1000);//0x1000 is the flag to open IE in new tab
         break;
       }
      browserCount--;

    }
Gokul
  • 788
  • 2
  • 12
  • 30
1

Unless iexplore.exe has some parameters that you can pass to it, I'm not sure if you can.

All the code you have is doing is launching a new IE process, so I can't see how it would be able to make use of a process that was already running.

Out of interest, if you know that there is already a browser running, why are you using this method for navigation?

Fiona - myaccessible.website
  • 14,481
  • 16
  • 82
  • 117