How do I start a process from C#?

后端 未结 12 2015
北荒
北荒 2020-11-22 03:38

How do I start a process, such as launching a URL when the user clicks a button?

12条回答
  •  渐次进展
    2020-11-22 04:09

    Include the using System.Diagnostics;.

    And then call this Process.Start("Paste your URL string here!");

    Try something like this:

    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Diagnostics;
    
    namespace btnproce
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                string t ="Balotelli";
                Process.Start("http://google.com/search?q=" + t);
            }
        }
    }
    

    Please note that it is a sample ASP.NET page as an example. You should try and improvise a little bit.

提交回复
热议问题