I have a C# application that includes the following code:
string file = "relativePath.txt";
//Time elapses...
string contents = File.ReadAllText(file);
This works fine, most of the time. The file is read relative to the directory that the app was started from. However, in testing, it has been found that if left alone for about 5 hours, the app will throw a FileNotFoundException
saying that "C:\Documents and Settings\Adminstrator\relativePath.txt" could not be found. If the action that reads the file is run right away though, the file is read from the proper location, which we'll call "C:\foo\relativePath.txt"
What gives? And, what is the best fix? Resolving the file against Assembly.GetEntryAssembly().Location
?