Loading a file into a TextBox

  • Thread starter Thread starter MSDousti
  • Start date Start date
M

MSDousti

Hi

How can I load a text file into a TextBox?

I have used System.Text.StringBuilder for fast loading. This method
works fine under windows XP, but it does not work in windows 98.

Any idea is appreciated.
thnx in advance.
 
Hi MSDousti,

Can you suply some code, because this sounds strange,

I asume you read a file with a database or a streamreader in a stringbuilder
and than you say something as
\\\
me.textbox1.text = sb.tostring
///

Cor
 
MSDousti said:
How can I load a text file into a TextBox?

I have used System.Text.StringBuilder for fast loading. This
method works fine under windows XP, but it does not work in windows
98.

"Does not work" means? Wrong result? Which result? Exception?
Relevant code? The Stringbuilder shouldn't be a problem.
 
* (e-mail address removed) (MSDousti) scripsit:
How can I load a text file into a TextBox?

I have used System.Text.StringBuilder for fast loading. This method
works fine under windows XP, but it does not work in windows 98.

Please be more specific. Error message? What's not working as expected?

"Post code!"
 
Hi again,
Excuse me for my strange explanations about the situation.
Really, that was because of the "strange" situation that was happened!

I have played with my app an hour or two, and finally I found out the
reason.

As I have explained before, when I load a file into my TextBox (called
mainTB) in windows XP, there is no problem. But in windows 98, nothing
shows up. I think that's because of the file size. When file size is
less than 40KB or so, there's no problem in 98. But for larger files,
the problem arises. My app is not supposed to handle very large files.
I think the largest file it should handle is about 5MB. This strange
thing does not take place in XP.

(More details:)
When I paste a text more than 40KB into mainTB, nothing happenes. But
I can paste texts with size less than 40KB normally.

If u want to know more details, here u r (I have enhanced my code, so
that it doesn't use StringBuilder anymore):

If OpenFileDialog1.ShowDialog(Me) = DialogResult.OK Then
Dim sr As StreamReader
sr = File.OpenText(OpenFileDialog1.FileName)
mainTB.Text = sr.ReadToEnd
sr = Nothing
END If


Another notice:
In windows 98, notepad cannot open large files and asks us if we want
to open the file with wordpad. Is this problem related to mine?

If the problem is related to TextBox implementation in windows 98,
what can I do? (I also cannot use RichTextBox, 'cause it is too slow
for loading even little files)
 
Hi MSdousti,

I have not direct an answer but when I had this problem I would split up my
problem first
If OpenFileDialog1.ShowDialog(Me) = DialogResult.OK Then
Dim sr As StreamReader
sr = File.OpenText(OpenFileDialog1.FileName)

I would read it line by line to a stringbuilder and then put that
stringbuilder to the textbox
mainTB.Text = sr.ReadToEnd

sr = Nothing

It has nothing to do with it, but why not just sr.close?

I hope this helps,

Cor
 
Sorry MsDousti,

I overlooked that you did use the stringbuilder, suddenly after posting I
remembered me that that was in your first post.

But why you not do that again and see step by step what gives the error, I
would even just put a string between it, while testing.

But now we know it is not the stringbuilder which what you started as
posible error causses it.

:-))

Cor
 
Hi Core.
I cannot load the file line by line into the textbox, because it takes
a lot of time. u can test this. Try a 1MB file, and open it in this
manner to see what happens.

sincerely urs,
MSD.
 
Hi MS,

I mean to point out where is the error?

And than bring it back in a more fast situation.

Cor
 
Hi
The problem is (as I said B4): when I open a file into a textbox using
the code I mentioned earlier, NOTHING SHOWS UP in the textbox. Please
try the code in windows 98 to open a 500KB (or larger) file. Does ur
textbox show the file?
 
Back
Top