OpenFileDialog로 텍스트 파일 읽기
OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == true)
{
FilePathLabel.Content = openFileDialog.FileName;
StreamReader sr = new StreamReader(openFileDialog.FileName);
List<Person> list = new List<Person>();
while(!sr.EndOfStream)
{
try
{
string line = sr.ReadLine();
string[] data = line.Split(',');
list.Add(new Person { name = data[0], age = data[1], info = data[2] });
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
StudentList.ItemsSource = list;
}