i have to read 10 lines from the middle of a file, i tried to use seek method but it requires number of bytes. i dont know how many bytes will be contained in 10lines. how can i tell seek to read 10 lines from a specified location.
If the file you're trying to read is a textfile, then you can use the TextReader's ReadLine method.
Try this and see if it helps.
TextReader reader = New StreamReader("<file to read>");
string line = "";
int startReadingHere = <enter line number here>;
int lineIndex = 0;
int readLines = 0;
while (reader.Peek() != -1)
{
if (lineIndex >= startReadingHere && readLines < 10)
{
line = reader.ReadLine();
//Do something with the string
readLines += 1;
}
lineIndex += 1;
}