Opening a file into a textbox

  • Thread starter Thread starter AMP
  • Start date Start date
A

AMP

Hello,
I'm not sure this is the best way but, I have a txt file I want to put
into a TextBox:

OpenFileDialog opnFile = new OpenFileDialog();
opnFile.Filter = "txt files (*.txt)|*.txt|All files
(*.*)|*.*";
opnFile.ShowDialog();
Stream openStream = opnFile.OpenFile();
StreamReader openReader = new StreamReader(openStream);


How do I get the stream into the Textbox AND Is this the best way of
doing this?
Thanks
Mike
 
You can't really put the stream itself into the textbox; perhaps just:

myTextbox.Text = File.ReadAllText(filePath);

Marc
 
Hi,

You just do StreamReader.ReadToEnd

Also remember to set the TextBox to multiline
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top