Some time we need to run or execute a batch file inside our code behind using the c# code, for that reason here I am going to show that how can we run a batch file inside the code behind. We can also pass the required parameter to run the file. Please check the following code.
try
{
System.Diagnostics.Process() objProcess = new System.Diagnostics.Process(); // Create the process object
objProcess.StartInfo.FileName = "c:\\Anil\\testAnil; //batch File Name
objProcess.StartInfo.Arguments = "c:\\Anil\\testAnil" + strXmlFileName;//paramter file name
objProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
objProcess.Start();
//Wait until the process passes back an exit code
objProcess.WaitForExit();
//Free resources associated with this process
objProcess.Close();
}
catch (Exception ex)
{
MessageBox.Show("Could not start process " + FileNameNew, "Error");
}
{
System.Diagnostics.Process() objProcess = new System.Diagnostics.Process(); // Create the process object
objProcess.StartInfo.FileName = "c:\\Anil\\testAnil; //batch File Name
objProcess.StartInfo.Arguments = "c:\\Anil\\testAnil" + strXmlFileName;//paramter file name
objProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
objProcess.Start();
//Wait until the process passes back an exit code
objProcess.WaitForExit();
//Free resources associated with this process
objProcess.Close();
}
catch (Exception ex)
{
MessageBox.Show("Could not start process " + FileNameNew, "Error");
}
I hope this will solve your problem. Waiting for your comments..!! Happy Coding!!
ThanksAnil Kumar PandeySystem Architect, MVPMumbai, Maharshtra
No comments:
Post a Comment