I have a CSV file that I need to read all values from. But only from the last row which is newest. But I can't figure it out how to do it.
Im using streamreader now but that loops through the whole CSV file which can be very big.
I need to read two diffrent csv files(headers are the same but on diffrent location).
But how can I edit this code to only read from the last row? I have searched around but could not find anything that are the same as mine.
So this is how I been doing right now:
using (var reader = new StreamReader(path))
{
var headerLine = reader.ReadLine();
var headerValues = headerLine.Split(',');
var serialNumber = headerValues[66];
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
if (values[0] != "Index")
{
var analyseReport = new AnalyseReport();
analyseReport.SerialNumber = serialNumber;
foreach (var item in headerValues)
{
var headerName = item.Trim();
var index = Array.IndexOf(headerValues, item);
switch (headerName)
{
case "Index":
analyseReport.Index = Convert.ToInt32(values[index].Trim());
break;
case "Time":
analyseReport.TimeStamp = Convert.ToDateTime(values[index].Trim());
break;
case "Reading No":
analyseReport.ReadingNo = Convert.ToInt32(values[index].Trim());
break;
case "Duration":
analyseReport.Duration = values[index].Trim();
break;
case "Type":
analyseReport.Type = values[index].Trim();
break;
case "Units":
analyseReport.Units = values[index].Trim();
break;
default:
break;
}
}
analyseReportList.Add(analyseReport);
}
}
return analyseReportList;
}