Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert text from a text file into a Label Control in C#

Could someone demonstrate how to insert text from a text file e.g. test.txt into a Label control on a visual C# form please

like image 597
Mike Avatar asked Jun 04 '11 20:06

Mike


People also ask

How do I add text to a text file in C#?

AppendText() Method in C# with Examples. File. AppendText() is an inbuilt File class method which is used to create a StreamWriter that appends UTF-8 encoded text to an existing file else it creates a new file if the specified file does not exist.

What is Label control in C#?

A Label control is used as a display medium for text on Forms. Label control does not participate in user input or capture mouse or keyboard events. A Label control is used as a display medium for text on Forms. Label control does not participate in user input or capture mouse or keyboard events.


2 Answers

You leave much to the imagination as to where you currently are with this and from which point you need help, but in the simplest form, try this:

theLabel.Text = File.ReadAllText(pathToFile);
like image 174
Grant Thomas Avatar answered Sep 19 '22 18:09

Grant Thomas


label.Text = File.ReadAllText("test.txt");

File.ReadAllText Method

like image 35
Alex Aza Avatar answered Sep 17 '22 18:09

Alex Aza