Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display the contents of a text file in a WPF TextBox while retaining the formatting?

What i want to do, is get the content of a *.Txt file, into a textbox, and if possible retain the formatting.

now, i found this site here: http://weblogs.asp.net/lduveau/archive/2008/03/02/load-a-txt-file-in-a-textbox.aspx That discribes an option 2 where you just add a .txt resources file, and read that to the textbox like this:

txtDisclaimer.Text = Resources.Common.disclaimer_en;

But within my WPF application, the Resources.Common part does not exist, and thus not work. Anyone have a clue how it should be done in WPF? Or can tell me a better way of getting text file content to a textbox ?

like image 768
Dante1986 Avatar asked Dec 17 '22 04:12

Dante1986


1 Answers

You can simply do

txtDisclaimer.Text = File.ReadAllText("Path of your File");

To keep the formatting use the overload

File.ReadAllText Method (String, Encoding)

like image 64
Haris Hasan Avatar answered Feb 08 '23 23:02

Haris Hasan