I have a file with products and prices, I need to write then to database, however I am trying to read a file and it reads only 1000 rows, and it says it is end of file although file has over 120000 rows. Look like reader is reading some rows from start of the document then some random from the middle and then some from the end of the file. Even if i do not write them to database and only writing them to database I got same result. Here is my code:
public async Task LoadProductsFromExcel()
{
var file = @"F:\Links\productsToImport.csv";
var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read);
using (var streamReader = new StreamReader(fileStream))
{
while (!streamReader.EndOfStream)
{
var line = streamReader.ReadLine();
var data = line.Split(new[] { ';' });
var product = new Product() { Name = data[1], Code = data[0]};
context.Products.Add(product);
Console.WriteLine(data[0]+" "+ data[1]);
}
}
await unitOfWork.CompleteAsync();
}
Is there a problem with buffer of stream or some any other problem? Or maybe I am reading a file wrong.