473,378 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Load text into textbox (Delphi-style)

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
Nov 17 '05 #1
3 4963
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]
- mv*@spam.guard.caspershouse.com

"Chris" <no****@nospam.be> wrote in message
news:8v********************************@4ax.com...
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

Nov 17 '05 #2
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
"Nicholas Paldino [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Chris" <no****@nospam.be> wrote in message
news:8v********************************@4ax.com...
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


Nov 17 '05 #3
text2Parse.Text = File.ReadAllText(openFileDialog1.FileName); works
just fine.

Thanks!
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: MJL | last post by:
Suppose you have a perl program that is called by a web page to generate another web page. The program is written to load data from a text file on the server and make certain substitutions in the...
1
by: David Dvali | last post by:
How can I load text from file to TextBox?
4
by: harish | last post by:
Hi friends Can any one know how can i load text box run time in vb application.
4
by: Husam | last post by:
Hi EveryBody: How can I load data from text file to textBox ? any help will be appreciated regard's Husam
2
by: jzheng22 | last post by:
Hi all, I am new to VB .NET. I am currently wring a simple GUI, a TextBox (multilined), a button and an OpenFileDialog. When user click the button, the OpenFileDialog fired and after user...
1
by: Dragan Ristic | last post by:
Can any one tell how can I load text from log file (.log, .txt) in ListView control (Details view). I have log file like this: Date and Time ; User Name ; Some event Date and Time ; User Name ;...
3
by: thetechgeek | last post by:
Hey all, I was wondering, how could I load text from an external file? It would be located locally on the server, probably in the same file path. Also, what format could I make the file in, so...
11
by: asmx126453 | last post by:
Hey Guys i need help with this last thing i cant get to work The error i get with it is: NullReferenceException was unhandled by user code Object reference not set to an instance of an...
8
by: davidson1 | last post by:
Hai friends... we use TinyPic to load image in the website(server)...so it can be accessed by URL..here i want to load text in the website...in case i want to load with specific size...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.