C # Downloading a file from the command line?

I am relatively new to C # and I have small problems.

I am creating a program in which I want to download a file from the command line. For instance:

MyProgram.exe C:\ExcelDocument.xls
+3
source share
2 answers

in the method of Mainyour program, the string array parameter argsfor the method will contain any command line parameters. The args array will contain 1 value for each element, separated by spaces, which is not enclosed in quotation marks (")

So

myprograme.exe c:\my documents\file1.xls 

will result in 2 arguments:

c:\my
documents\file1.xls

then

myprograme.exe "c:\my documents\file1.xls"

will result in 1 value in args:

c:\my documents\file1.xls

you can access the parameters using an indexer:

string file = args[0];

assuming the file is the first argument.

, , , .

+6

args [0].

public static void Main(string [] args)
{
    //This will print the first argument you passed in on command line.
    Console.WriteLine(args[0]); 
}
+4

All Articles