The sample project I created perform the following tasks:
1. Ask for CSV file location.
2. Read the data from CSV file and put it on ListView control.
CSV format used is:
Make sure you already included the following namespaces
To retrieve data from CSV file, use the following code:
string csvlines = File.ReadAllLines(@txtCSVFile.Text);
var query = from csvline in csvlines
let data = csvline.Split(',')
ID = data,
FirstName = data,
LastName = data,
Email = data
Take note of the new keyword "let" which is used inside LINQ queries to create temporarily variables.
To view the sample Visual Studio 2008 project. Download it from here.
For more LINQ coding tips, subscribe now