I received the following question over the weekend:
I’ve made a C# form application and I need to send a report name at runtime. How do I add an incoming parameter to the command line? Such as “crFORM.exe Shipform.rpt”
I have to assume the question relates more to how to retrieve the parameter in the code than how to pass it because the example shows how we’d pass it. All WinForms CSharp programs have a static method called Main() that looks something like this:
1 | [ ] |
If you are using Visual Studio 2008 to build your applications, this code can be found in Program.cs. To accept parameters you will need to modify this method so that it accepts a string array as a parameter. Most people name this parameter “args.”
1 | [ ] |
If a parameter was passed, args will have a length greater than zero. To retrieve the command line arguments all you need to do is retrieve the parameters out of args.
1 | [ ] |