Can't read from file in same folder
I am trying to select a random line from a txt file in the same folder, it is called "pickupDA.txt" and so I have tried to get the lines from it with File.ReadAllLines("pickupDA.txt"); but it doesnt work. i have tried with "./pickupDA.txt" and "/pickupDA.txt" and ".\pickupDA.txt", none of it works
4 Replies
That code tries to read from the user's current working directory. By default, that's the folder which contains your application's .exe file, but the user can change that
But, if your
pickupDA.txt
is next to your .cs files, then it won't be next to your .exeso i should reference the txt file from the "perspective" of the exe?
where is that exe located in maui?
google isnt helping
If the text file is part of the project, just set up a copy of newer action on the item
Can be done in the properties in the solution explorer
I would add a line to print the path of the executable, then run it
Like so "Console.WriteLine(System.IO.Path.GetDirectoryName(Application.ExecutablePath));"
Then I would change the path to go back as many directories as your text file is in like "../../../pickupDA.txt"
Or just put the text file in the same printed path