I'm trying to read from a document that has a list of students with their first name, last name, student id, email.
I've successfully created/designed the xmal file with a listBox (see attachment).
But I'm having difficulties writing the code in the try section, which will read from the document into the listBox in such order that each of the specific read data must go under those relevant textblocks. for instance first name should go under first name, and so on.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
namespace MemberList
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
string filePath = @"C:\Users\User\DEMO\MemberList.csv";
private void Member_List_Load(object sender, EventArgs e)
{
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs, Encoding.Default);
List<string> lines = File.ReadAllLines(filePath).ToList();
while (!sr.EndOfStream)
{
try
{
foreach (var line in lines)
{
string[] entries = line.Split(';');
textblock1 = entries[0];
textblock2 = entries[1];
textblock2 = entries[2];
textblock2 = entries[3];
}
}
catch (Exception)
{
throw;
}
finally
{
}
}
}
}
}