I have a json file I am trying to read via a StreamReader
. The json is in the same directory as my code. However, any method for loading the file (GetFullPath()
, GetDirectoryName()
, etc) is always looking in the \bin\Debug\netcoreapp3.1
directory, where it obviously is not. I have tried all the different versions
I think that has more to do with an issue with netcoreapp than anything else. How do I get it to just load the file in the same directory?
Option 1: Don't include a path at all. That will use the current directory, which by default is the directory of the executable file. I mention this for completeness, but it probably won't work, because your executable is not in the same folder as your code!
Option 2: Look for the file in Visual Studio's Solution Explorer. The properties for the file there will include an option to
Copy to Output Directory
that is probably currently set toDo not copy
. You want this to beCopy always
orCopy if newer
. Then, when you build your project, it will place the file in theDebug
orRelease
folder with your program.