question

TonyGirgenti-0462 avatar image
0 Votes"
TonyGirgenti-0462 asked TonyGirgenti-0462 answered

How to open new Firefox window using C# System.Diagnostics.Process.Start

Hello,

I'm using Visual Studio Community 2019 Version 16.8.4 with .NET Framework 4.8.04084 on a laptop computer developing a C# windows form program.

I want to open a new Firefox window from my program.

I can open a new tab in an existing Firefox window using the following code:

 private void CreateNFLStats_Click(object sender, EventArgs e)
           {
                //// Got this here: https://docs.microsoft.com/en-us/troubleshoot/dotnet/csharp/start-internet-browser
                string target = "https://www.nfl.com/stats/team-stats/offense/passing/2021/reg/all";
    
                try
                {
                     System.Diagnostics.Process.Start("firefox.exe", target);
                     Application.Exit();
                }
                catch (System.ComponentModel.Win32Exception noBrowser)
                {
                     if (noBrowser.ErrorCode == -2147467259)
                          MessageBox.Show(noBrowser.Message);
                }
                catch (System.Exception other)
                {
                     MessageBox.Show(other.Message);
                }
    
           }

How do I open the URL in a new Firefox Window?

Any help would be gratefully appreciated.

Thanks,
Tony

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered

Try this:

 Process.Start( "firefox.exe", "-new-window " + target )


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TonyGirgenti-0462 avatar image
0 Votes"
TonyGirgenti-0462 answered

Excellent Viorel!

That worked perfectly.

Thanks for your help.
Tony

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.