if you want that how many lines in the text file than you can use this code
private int GetTotalLines(string FileNameWithPath)
{
string[] bt = null;
if (System.IO.File.Exists(FileNameWithPath))
{
bt = System.IO.File.ReadAllLines(FileNameWithPath);
}
return bt.Length;
}
if you want to find line no in which your search string is exist than you can use this function
private int GetLinesNoFromFile(string FileNameWithPath,string searchString)
{
string[] bt = null;
if (System.IO.File.Exists(FileNameWithPath))
{
bt = System.IO.File.ReadAllLines(FileNameWithPath);
}
for (int i = 0; i < bt.Length; i++)
{
string str = bt[i].ToString();
if (str.Contains(searchString))
return i;
}
return -1;
}