C# open url in default browser in c# windows application(Winforms Process.Start)

Lionsure 2020-08-08 Original by the website

Click some hyperlink text on the software interface to open a web page in the default browser. How should this function be implemented in C# Winforms development? The method is very simple. C# provides an open method Process.Start(), which can be achieved by passing the URL to the opened method.

Some software has a lot of hyperlink text, click one to open a webpage, how is this achieved? In fact, no matter how many hyperlinks, you can use the Process.Start() method. Just click a link and pass a URL to it.


1. C# open url in default browser directly(Open url by C# process start)


Or System.Diagnostics.Process.Start("IEXPLORE.EXE", "Url");

IEXPLORE.EXE is not case-sensitive, and it is not necessary to write .exe, that is, iexplore.


Tip: If the code is to be encrypted with an encryption tool, the web page cannot be opened through the form of System.Diagnostics.Process.Start("url"); after encryption. The namespace must be referenced(i.e. using System.Diagnostics;), the code write the class directly, that is, Process.Start("url"); to open the web page.



2. C# open url in default browser by creating a new Process object

For ease of use, we encapsulate the code in a method, the code is as follows:

using System.Diagnostics;

/// <summary>
        /// Open url in c# windows application
        /// </summary>
        /// <param name="url">URL of the page to open</param>

        public void OpenUrl(string url)
                Process pro = new Process();
                pro.StartInfo.FileName = "iexplore.exe";
                pro.StartInfo.Arguments = url;

Call: OpenUrl("http://www.liangshunet.com/");