I use this handy method to parse a .csv file:
Here is where I call the method and then iterate the data:
List<string[]> data = new List<string[]>();
data = parseCSV(path);
foreach (string[] item in data)
{
}
"path" is the location of your file.
public List<string[]> parseCSV(string path)
{
List<string[]> parsedData = new List<string[]>();
try
{
using (StreamReader readFile = new StreamReader(path))
{
string line;
string[] row;
while ((line = readFile.ReadLine()) != null)
{
row = line.Split(',');
parsedData.Add(row);
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
return parsedData;
}