StreamReader.ReadLine()

  • Thread starter Thread starter Tarren
  • Start date Start date
T

Tarren

Hi:

Question which might have something to do with encoding?

I have a text file and I use the following code to iterate through.

StreamReader oStreamFile = new StreamReader(sFileName);

string sRowText;
while ((sRowText = oStreamFile.ReadLine()) !=null)
{
//dosomething with the text;
}

It pulls the first line fine. When it returns to the beginning of the loop,
it immediately negates the loop. But in the file there are 16000 lines, so
I know it is ok but do not know why it thinks there is only one line. I ran
through standard troubleshooting. The stream is the right length and is
pulling in the file, so I know it is not messing up there.

The weird thing is that it takes the first line fine.

These are db generated files that are transmitted to my file store via FTP.
Any help is appreciated. Thanks.
 
Tarren,
2 MSDN example I found. Looks like your mixing them. I'd try one or
the other to see if it works for you.


using (StreamReader sr = new StreamReader(path))
{
while (sr.Peek() >= 0)
{
Console.WriteLine(sr.ReadLine());
}
}


// Open the stream and read it back.
using (StreamReader sr = File.OpenText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}

Jason Newell, MCAD
Software Engineer
 
Back
Top