HiTmAN Posted August 10, 2003 Posted August 10, 2003 I am using the following code: Dim rdBfr As New System.IO.StreamReader(dlgO.FileName) Do While rdBfr.Read() txtOriginal.Text = txtOriginal.Text & rdBfr.ReadLine() Loop rdBfr.Close() However, the aplication crashes when I use it. What is the problem? Quote
*Experts* Volte Posted August 10, 2003 *Experts* Posted August 10, 2003 Try changing the Read() to Peek(). Anyway, you can read the whole thing like this:txtOriginal.Text &= rdBfr.ReadToEnd() Quote
Leaders dynamic_sysop Posted August 11, 2003 Leaders Posted August 11, 2003 and you may not need to use Do While , rather you can use While Not rdBfr.Peak() , here's a quick example : Dim dlgO As New OpenFileDialog() With dlgO .Filter = "text|*.txt" .InitialDirectory = "D:\" If .ShowDialog = DialogResult.OK Then Dim rdBfr As New IO.StreamReader(New IO.FileStream(dlgO.FileName, IO.FileMode.Open)) While Not rdBfr.Peek '/// make sure it only reads till it gets to it's peak. txtOriginal.AppendText(rdBfr.ReadLine & Environment.NewLine) End While End If End With Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.