Link to home
Start Free TrialLog in
Avatar of valentinemhlanga
valentinemhlangaFlag for United States of America

asked on

Count Number of Lines in text file c# and also write to the same file .

hello ,

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;
                string line;
                TextReader reader1 = new StreamReader(@"\sqlfile.txt");
                while ((line = reader1.ReadLine()) != null)
                {
                  count++;
                }
                reader.Close();
ASKER CERTIFIED SOLUTION
Avatar of Kimputer
Kimputer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial