Dante1986
Dante1986

Reputation: 59989

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 ?

Upvotes: 4

Views: 16690

Answers (1)

Haris Hasan
Haris Hasan

Reputation: 30127

You can simply do

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

To keep the formatting use the overload

File.ReadAllText Method (String, Encoding)

Upvotes: 12

Related Questions