openfiledialog for text editor

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi,

i have an openfiledialog and a multiline textbox. i want to be able to open
text documents in it. can you please give me the c# code to do this?

by the way, the textbox is called textBox1 and the openfiledialog is called
openFileDialog1
 
Alvo,

Once you get the name of the file from the file dialog, you will want to
use the StreamReader class to read the contents of the file into a string
(through the methods on the StreamReader, most notably, ReadToEnd). Once
you do that, you can set the Text property of the textbox to the string and
the contents will be in there.

Hope this helps.
 
hi,

i am very new to c# and i'd be grateful if you answered in a little less
technical terms. by the way, where it says it answered my question, it
didn't. i clicked the wrong button

--
Alvo von Cossel I of Germany


Nicholas Paldino said:
Alvo,

Once you get the name of the file from the file dialog, you will want to
use the StreamReader class to read the contents of the file into a string
(through the methods on the StreamReader, most notably, ReadToEnd). Once
you do that, you can set the Text property of the textbox to the string and
the contents will be in there.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Alvo von Cossel I said:
hi,

i have an openfiledialog and a multiline textbox. i want to be able to
open
text documents in it. can you please give me the c# code to do this?

by the way, the textbox is called textBox1 and the openfiledialog is
called
openFileDialog1
 
Back
Top