How to start a process or a program in C#
In the following example we will see how to open a program or start a process in C# by using the Process class. We start Microsoft Word.
First we add the directive "using System.Diagnostics;"
Then in button click event we add this code:
If we want to start a Microsoft Word (.docx) file, we use an overload of Start method that accepts a ProcessStartInfo object. The code below describes how to open a (.docx) file:
First we add the directive "using System.Diagnostics;"
using System.Diagnostics;
Then in button click event we add this code:
private void button1_Click(object sender, EventArgs e)
{
string ProgramName = "winword.exe";
Process.Start(ProgramName);
}
If we want to start a Microsoft Word (.docx) file, we use an overload of Start method that accepts a ProcessStartInfo object. The code below describes how to open a (.docx) file:
private void button1_Click(object sender, EventArgs e)
{
string ProgramName = "winword.exe";
Process process = new Process();
process.StartInfo.FileName = ProgramName;
process.StartInfo.Arguments="D:\\MyDocument.docx";
process.Start();
}
How to start a process or a program in C#
Reviewed by Bloggeur DZ
on
11:21
Rating:
Aucun commentaire: