Groups | Blog | Home
all groups > c# > july 2005 >

c# : Load text into textbox (Delphi-style)


Brendan Grant
7/18/2005 1:57:04 PM
If I’m not mistaken ReadAllText() is part of the 2.0 Framework, and if you
are using 1.0 or 1.1 you would have to take a step back and do something a
little longer such as:

memo1.Text = File.OpenText("myfile.txt").ReadToEnd();

You are still ultimately dealing with a StreamReader, however a little more
indirectly and inline with Nicholas’s example.

Brendan


[quoted text, click to view]
Nicholas Paldino [.NET/C# MVP]
7/18/2005 4:38:47 PM
Chris,

You can use the static ReadAllText method on the File class in the
System.IO namespace, like so:

// Set the text in the textbox.
textbox1.Text = File.ReadAllText("filename");

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

[quoted text, click to view]

Chris
7/18/2005 10:28:14 PM
Hi,

In Delphi there is the possibilty to load a textfile into a textfield
(memo) without writing too much code. It goes like
memo1.Lines.LoadFromFile('myfile.txt');

What is the C# equivalent (without making use of a streamreader)?

Cheers,

Chris
7/19/2005 10:30:02 AM
text2Parse.Text = File.ReadAllText(openFileDialog1.FileName); works
just fine.

AddThis Social Bookmark Button