I am trying to pull a text file called Teams.txt
and have it displayed in a ListBox
.
I have the Teams.txt
inside the Visual Studio project file, but it is not reading it.
Does the file have to be in a certain place in order to be read?
private void BtnList_Click(object sender, EventArgs e)
{
try
{
const int SIZE = 100;
int[] numbers = new int[SIZE];
int index = 0;
StreamReader inputfile;
inputfile = File.OpenText("Teams.txt");
while (index < numbers.Length && !inputfile.EndOfStream)
{
numbers[index] = int.Parse(inputfile.ReadLine());
index++;
}
inputfile.Close();
foreach (int value in numbers)
{
lstTeams.Items.Add(value);
}
}
catch
{
MessageBox.Show("Error.");
}
}