Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to call an exe like this from the command prompt
@BatchFiles + "\\ABC.exe " + File + " " + template +"
File and template are two folder paths having a txt file and a doc file.

I have created a Windows form in c# and created an exe, when i need to call the exe
how to set the File and template value at the load event in windows application so it will take the same value from the command prompt.

For time being i hardcode the path

C#
string mhtfile = @"D:\Users\\Desktop\_1707.mht";
 string template = @"C:\Files\Template\N.docx";


Please help me how to set these values with out hardcode.

Thanks in advance
Posted
Updated 13-Jan-15 1:31am

Why not use the program arguments:
C#
string[] args = Environment.GetCommandLineArgs();
if (args.Length >= 3)
    {
    string mhtfile = args[1];
    string template = args[2];
    }

Then just run your app with the values:
MyApp "D:\Users\\Desktop\_1707.mht" "C:\Files\Template\N.docx"
 
Share this answer
 
Comments
Renjith_R 13-Jan-15 7:33am    
Thanks for your quick reply :)
You can use the following Code in the Load event.
This works the same as it does in an Console Application.

MSDN Referenz

C#
string[] args = Environment.GetCommandLineArgs();

foreach(string arg in args)
{

}
 
Share this answer
 
Comments
Renjith_R 13-Jan-15 7:33am    
Thanks for your quick reply :)
You can read the values using Environment.GetCommandLineArgs:
http://msdn.microsoft.com/en-us/library/system.environment.getcommandlineargs%28v=vs.110%29.aspx[^]

But I would recommend using a package like CommandLineParser:
https://commandline.codeplex.com/[^]

Good luck!
 
Share this answer
 
Comments
Renjith_R 13-Jan-15 7:34am    
Thanks for your quick reply :)
E.F. Nijboer 14-Jan-15 3:48am    
No problem :)
If this answer helped, please mark it as answer.

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