0

I have a charp file and have created in JetBrainsRider -> Console Project. In main method, there is code as below

static void Main(string[] args)
        {
            string FileNamePrefix = string.Empty;
            string InfoFileName = string.Empty;

            if (args.Count() > 0)
            {
                FileNamePrefix = args[0];
            }
            else
            {
                Console.Write("Enter File Name (no extension): ");
                FileNamePrefix = Console.ReadLine();
            }

            InfoFileName = "InOut\\" + FileNamePrefix + "-INFO.TXT";
            if (!File.Exists(InfoFileName))
            {
                Console.WriteLine("{0} does not exist.  Run Terminated", InfoFileName);
                return;
            }
}

When I place a TestInput-INFO.TXT file in project folder and give name in readline input, it gives error:

Enter File Name (no extension): TestInput
InOut\TestInput-INFO.TXT does not exist.  Run Terminated

Where should I put my input file? Code

File Location

Aakash Patel
  • 549
  • 5
  • 19

1 Answers1

1

It is relative to the current directory — see Environment.CurrentDirectory.

When executing a program from within the IDE, the exe file is located in the bin folder, and hence that is the current directory for the process.

Ondrej Tucny
  • 27,626
  • 6
  • 70
  • 90