06-21-2004, 12:54 PM
Does anybody know how to open a text file and load it into RichTextBox without using the OpenFileDialog?
I want a specific text file (the path will be hard coded, for now) to open and be read into a RichTextBox when the form opens.
06-21-2004, 01:06 PM
How big is the text file? The string object in .Net should be able to hold the amount of the data that you need. If we are talking about a REALLY big file, we would have to tweak this, but this alone, should be fine:
Dim myOutput As StreamReader
Dim sValues As String
myOutput = New StreamReader("C:\test\Data.txt")
sValues = myOutput.ReadToEnd
Me.RichTextBox1.Text = sValues
06-21-2004, 01:25 PM
That works great!!
06-21-2004, 01:28 PM
No problem, glad to help. Good luck!
06-21-2004, 03:09 PM
umm... wouldnt it be easier to do rtb.loadfile(path as string) if your just doing something that simple?
06-21-2004, 07:44 PM
Yes, you could do it that way too. But what exactly is wrong with the StreamReader method? There is nothing wrong with it. There are several potential ways to do this..I presented the first one that came to mind. But thanks for your input.