Count Number of Lines in text file c# and also write to the same file .
Posted on 2015-01-15
I am trying to populate a field in my text file and it needs the number of records in the text file, meaning the lines.
each time I try to use the code below , I get an error saying that the file is being used as I am writting other records to it .
int count = 0;
TextReader reader1 = new StreamReader(@"\sqlfile.txt");
while ((line = reader1.ReadLine()) != null)