Try to dedicate the file in a fixed sub directory:
\TicTacToe.exe \settings\settings.cfg
So the path is dependent of your executable file.
You'll fetch the directory by calling Directory.GetCurrentDirectory()
You can set a desired directory by setting Environment.CurrentDirectory
A common way to handle this case is the one described above.
Another would be to use user specifiy directories like the %appdata% path and create a dedicated directory there.
%appdata%\TicTacToe\settings.cfg
Everytime your application starts it should lookup the folder %appdata%\TicTacToe\
If it is present, your application has been executed with this user. If not, just create a new one, so we know it's the first run.
You can get the %appdata% path by calling
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Example of what i would have done
private void setUp(){ string filename = "settings.cfg"; string dir = "TicTacToe"; string appdata =Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string fullpath = Path.Combine(Path.Combine(appdata,dir),filename); //check if file exists, more accurate than just looking for the folder if(File.Exists(fullpath )){ //read the file and process its content }else{ Directory.CreateDirectory(Path.Combine(appdata,dir)); // will do nothing if directory exists, but then we have a bug: no file, but directory available using (FileStream fs = File.Create(fullpath)) { Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file."); // Add some information to the file. fs.Write(info, 0, info.Length); } } }
Hope it helped.
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Tic Tac Toe", "HighScores.txt").