0

I am trying to store a leaderboard locally for the game I am working on. To do this, I have added a text file to the resource folder inside my program. I am attempting to write to and read from this file in order to fill up my leaderboard, but I cannot figure out a way to access it inside the C# program. Everything online is extremely difficult to understand, and I am fairly new to this language. I will provide screenshots of what I think to be important to this.

StreamReader

StreamWriter

TextFile

I cannot put the text file image into this question but I can input the code.

This is for the string writer part...

`` string fileName = "Scoreboard.txt";

string filePath = Path.Combine(FileSystem.AppDataDirectory, fileName);

    using (StreamWriter writer = new StreamWriter(filePath, true))
    {
        writer.WriteLine(Convert.ToString(balance));
    }

``

This is for the string reader part...

`` string fileName = "Scoreboard.txt";

string filePath = Path.Combine(FileSystem.AppDataDirectory, fileName);

    using (StreamReader reader = new StreamReader(filePath))
    {
        string line = reader.ReadLine();
        while(line != null)
        {
            LeaderBoard.Add(Convert.ToInt32(line));
            line = reader.ReadLine();
        }
    }

``

I've tried multiple ways of accessing the file, but it will not work, and I cannot use my file path as it uses my username, which means it would not work for everyone. Any help would be greatly appreciated.

  • Is this a WPF application? Local storage as tagged is a memory location within the browser, so it is not relevant to the question. I am assuming what you mean is storing a file on the local machine this application your developing is running on? Also instead of using plain unstructured `.txt` consider to use something structured like JSON. – Mushroomator Apr 24 '23 at 21:45
  • Is there any reason why we can't see the text file? It would be very helpful - if you need to, maybe you could only show a small section or just some example content? (ideally created by the program) – CoderMuffin Apr 27 '23 at 19:45
  • Also, does this help? https://stackoverflow.com/questions/3314140/how-to-read-embedded-resource-text-file – CoderMuffin Apr 27 '23 at 19:48

0 Answers0