This is my code, it reads from a text file and places it into the listbox on my form. If there is already something in the text file it works. But if I delete what's in the text file and run the program it crashes and gives me the error "Index was outside the bounds of the array."
at assignment.Request.Name = columns[1];
and I'm not sure why/how to go about fixing it.
public static List<Assignment> GetAssignment()
{
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
StreamReader textIn =
new StreamReader(
new FileStream(path3, FileMode.OpenOrCreate, FileAccess.Read));
List<Assignment> assignments = new List<Assignment>();
while (textIn.Peek() != -1)
{
string row = textIn.ReadLine();
string[] columns = row.Split('|');
Assignment assignment = new Assignment();
assignment.Employee.Name = columns[0];
assignment.Request.Name = columns[1];
assignments.Add(assignment);
}
textIn.Close();
return assignments;
}