I have a block of C# code that is trying to open a .txt file. This text file is in the same project as the block of code that's running. At this time, I'm trying to open the .txt file using the following:
var filePath = @"\Status\new.txt";
try
{
var content= File.ReadAllText(filePath);
}
catch (DirectoryNotFoundException)
{
Console.WriteLine("Unable to find " + filePath);
}
When this code runs, I get a DirectoryNotFoundException
. The console shows:
Unable to find \Status\new.txt
I changed the "Copy to Output Directory" property of the "new.txt" file to "Copy if newer". I can see the "new.txt" file in the "bin/Debug/netcoreapp2.1/Status/" directory.
I'm running this code currently via an MSTest project. I don't understand why I'm getting this exception though.