I have some code that saves data from a class to .csv files, but I am not sure how to read it back into a class so I can put it in a listview. Here is the code for the save:
SaveFileDialog save = new SaveFileDialog();
save.Filter = "Excel|*.csv";
if (save.ShowDialog() == DialogResult.OK)
{
StreamWriter sw = new StreamWriter(save.FileName);
try
{
sw.WriteLine("Name" + ";" + "Authors" + ";" + "Pages" + ";" + "Date" + ";" + "Price" + ";" + "Copies");
foreach (Book b in bookList)
{
string aux = "";
aux = string.Join(";", b.Authors);//I know I will probably need to change ';' here because it will have trouble reading it
sw.WriteLine(b.Name + ";" + aux + ";" + b.Pages + ";" + b.Date.ToString("dd.MM.yyyy") + ";" + b.Price + ";" + b.Copies);
}
}
catch (IOException ert)
{
MessageBox.Show(ert.Message);
}
catch (Exception ew)
{
MessageBox.Show(ew.Message);
}
finally
{
sw.Close();
}
}