Re: Small File Input Problem
You are using a stream, so when you call ReadLine( ) the position of the stream is being incremented. So, when you later call ReadToEnd( ) there is nothing left to read. Why not just create the string while you are looping through each line, i.e., get rid of the call to ReadToEnd( )?
Re: Small File Input Problem
make sure you set the textbox for the text to be MultiLine.
Code:
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
StringBuilder sb = new StringBuilder();
int counter = 0;
using (TextReader tr = new StreamReader(ofd.FileName))
{
while (tr.Peek() >= 0)
{
sb.AppendLine(tr.ReadLine());
counter++;
}
}
txtText.Text = sb.ToString();
txtCount.Text = counter.ToString();
}
Re: Small File Input Problem
Managed to get it working, thanks :)