-2

My c# program is a text editor which needs file name as an input parameter. In other words, I would like to start the c# EXE from a BAT file specifying which file to open. For example: "call C:\Temp\MyDotNetApp File1", where 'File1' is the input parameter for the program in C#.

Is this possible in C#? I can't find any tutorial on internet.

My code:

namespace CSVEditor{
     public partial class Form1 : Form { 
     public static string TAG = "";
     public static string FileLinnk = "";
}

public Form1()
    {
        InitializeComponent();          
    }
private void Form1_Load(object sender, EventArgs e)
    {
        //Input file to read
        File = "File1";// <----- This needs to be the input parameeter from BAT file.

        //
        FileLink = @"c:\temp" + File + ".csv";

        ReadCSV(FileLink);
    }

Cheers.

Rand Random
  • 7,300
  • 10
  • 40
  • 88
Andy
  • 79
  • 1
  • 7

1 Answers1

1

Just use Environment.GetCommandLineArgs;

string[] args = Environment.GetCommandLineArgs();
lucky
  • 12,734
  • 4
  • 24
  • 46