I am relatively new to C# and I am having a little trouble.
I am creating a program where I want to load a file from the command line. For example:
MyProgram.exe C:\ExcelDocument.xls
in the Main method of your program the args string array parameter to the method will contain any command line parameters. The args array will contain 1 value for each space separated element that is not enclosed in quotes (")
so
myprograme.exe c:\my documents\file1.xls
will result in 2 args:
c:\my
documents\file1.xls
whereas
myprograme.exe "c:\my documents\file1.xls"
will result in 1 value in args:
c:\my documents\file1.xls
you can access the params via the indexer:
string file = args[0];
assuming that the file is the first argument.
obviously you will still need to load the actual file, this will only give you the name give as a parameter to your program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With