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

Tony Girgenti 21 Reputation points
2021-10-30T20:56:27.357+00:00

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://learn.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

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,219 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Tony Girgenti 21 Reputation points
    2021-10-30T21:13:05.32+00:00

    Excellent Viorel!

    That worked perfectly.

    Thanks for your help.
    Tony

    0 comments No comments