I have made a program so that the user can track there fantasy football team the code below is from one of the forms that allows the user to pick their team under a specific set of rules. The issue here is not writing to the file it is reading from the file that was written too.
This file is in my resources and it contains the players the user entered. The issue is that the user has to access this text file and at this point it does not matter if the user can access edit the file or not this is a personal project for one person; however the way I have it set up this program will only run on my computer since the path I would use is the full path from the text files properties.
I have tried using the properties.Resources.resource as seen below and most recently I have tried using Application.StartupPath + "/FantasyFootball.txt". I still have not yet tried reflection because I am not sure if reflection is needed for this. The idea should be that I publish this program and it should work on any computer;however I get an exception when I try and run it outside of visual studio that the AppData folder could not be found.
So the question now is what actually happens when I press the publish button in visual studio? I get the setup file and the application files folder and the actual.application file and this ends up in my bin folder in the release folder in the app.Publish folder. I do not yet have the experience to know what this all means or what to do with it any suggestions?
private void btnShowRoster_Click(object sender, EventArgs e)
{
string masterRosterPath = Properties.Resources.FantasyFootball;/*
this is where the problem is I am not sure what to make the path
so that the user will be able to acess the file*/
FileStream fs = new FileStream(masterRosterPath, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
string playerIn;
string[] fields;
playerIn = sr.ReadLine();
const char DELIM = ',';
string player = " ";
while (playerIn != null)
{
fields = playerIn.Split(DELIM);
player = Convert.ToString(fields[0]);
lbRoster.Items.Add(player);
playerIn = sr.ReadLine();
}
sr.Close();
fs.Close();
btnShowRoster.Enabled = false;
MessageBox.Show("Click on a player to add them to your team", "Choose Team", MessageBoxButtons.OK,MessageBoxIcon.Information);
}