Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
2.14/5 (5 votes)
See more:
hi,

I want to know how to call a third party batch file from the app.config file. please help me out.



In my App.Config File i have written:

<add key="BatchFile" value="qs.bat">


in my .cs:
string sValue = ConfigurationManager.AppSettings["BatchFile"];
process.start(sValue);


but it is not working.


Thank you.
Posted
Updated 14-May-14 23:10pm
v6
Comments
David_Wimbley 15-May-14 1:25am    
What does this mean? What is the batch file? Is it csv? xml? fixed length? Is this for a console app? Winforms? webforms? mvc? What does executing it mean? Does it mean processing it? Picking up the file path and the using it in your application? Or do you just need to add the path to the appsettings and the use it in the app...there are a lot of "what ifs" that you didnt make clear. I feel like my last girlfriend with all these questions i'm asking.


Your question is pretty vague, if you can clarify with more detail what you want im sure you will get better answers...till then my crystal ball is out of order.
Member 10042156 15-May-14 2:56am    
It is a Windows batch file

app.config won't execute anything...
Well, your application can read settings from the config file. Use the ConfigurationManager class.
After reading the path of that batch file, have it start it. Use Process.Start for that purpose.
 
Share this answer
 
Comments
[no name] 15-May-14 3:27am    
That's about all you can do.
Try

C#
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = sValue; 
proc.StartInfo.UseShellExecute = true;
proc.Start();
 
Share this answer
 
Comments
Bernhard Hiller 16-May-14 2:56am    
Looks like there was an "expert" downvoting some solutions here.
 
Share this answer
 
Comments
[no name] 15-May-14 3:22am    
Nothing to do with the question. OP asked how to run batch file from config.app.
http://www.codeproject.com/Lounge.aspx?fid=1159&select=4820715&tid=4820624
[no name] 15-May-14 3:33am    
Its not for execution, do changes using batch file in web.config.
Thank u.
[no name] 15-May-14 3:34am    
Please read the question properly. Your answer is completely off topic and irrelevant.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900