0

I am writing a wpf application which should draw lines due points given in a file.

How can I pass a file in the command line to my c# program? For example something like

MyProgram.exe < file.txt

In addition how can I do this in visual studio for debugging? I know I can set command line args and can read them with

var args = System.Environment.GetCommandLineArgs().ToList();
OOPDeveloper89
  • 207
  • 5
  • 18

3 Answers3

0

You have to do is call the program in this way, "filedetails.exe myfile.txt"

Example :

C:\Users\FILEREADER>filedetails.exe myfile.txt
Nazmul
  • 575
  • 3
  • 18
0

How can I pass a file in the command line to my c# program? For example > something like

MyProgram.exe <file.txt

You can try this Console.OpenStandardInput()

Community
  • 1
  • 1
Shurick
  • 1
  • 1
0

I don't think it is possible to pass file content as a parameter. You currently pass file content correctly:

MyProgram.exe < file.txt

all you need is to read it, I put a small cmd application:

    static void Main()
    {
        string line;
        while ((line = Console.ReadLine()) != null)
        {
            Console.WriteLine(line);
        }
    }

In wpf application:

    public MainWindow()
    {
        InitializeComponent();
        var result = "";
        string line;
        while ((line = Console.ReadLine()) != null)
        {
            result += (line);
        }
        MessageBox.Show(result);
    }

Check here for more information about about command line redirections.

floatas
  • 170
  • 1
  • 8