How do I start a process, such as launching a URL when the user clicks a button?
class ProcessStart
{
static void Main(string[] args)
{
Process notePad = new Process();
notePad.StartInfo.FileName = "notepad.exe";
notePad.StartInfo.Arguments = "ProcessStart.cs";
notePad.Start();
}
}
I used the following in my own program.
Process.Start("http://www.google.com/etc/etc/test.txt")
It's a bit basic, but it does the job for me.
To start Microsoft Word for example, use this code:
private void button1_Click(object sender, EventArgs e)
{
string ProgramName = "winword.exe";
Process.Start(ProgramName);
}
For more explanations, check out this link.
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.
You can use the System.Diagnostics.Process.Start method to start a process. You can even pass a URL as a string and it'll kick off the default browser.
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "/YourSubDirectory/yourprogram.exe");
Process.Start(new ProcessStartInfo(path));