Click here to Skip to main content
15,898,374 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
I want to read from a text file and display its in a textbox .
I read the file line by line but it can not read enter character.
for example:
my text file is:
this is a test.
this is a test.
and textbox disply:
this is a test.this is a test.

please help me
Posted

I used the following code and it worked fine for me:
textBox1.Text= System.IO.File.ReadAllText(@"C:\test.txt");


I set the Multiline property of text box to true and executed the code.
My text box showed exactly the same formatted contents as in file.

Hope this help
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 28-Jan-11 9:31am    
This is a good as is way, in contrast to the answer by Estys.
--SA
Pravin Patil, Mumbai 28-Jan-11 10:05am    
I personally feel that this way is good only if file is of small size. But for big size files it just hangs. In that case reading line by line seems useful.
Pleas correct me if I am wrong.
Add an Environment.NewLine between the read lines.

textBox.Text + = Environment.NewLine + lineJustRead;


Cheers
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 28-Jan-11 9:30am    
This is good way with conversion of text end-of-line to a current system.
--SA
Pravin Patil, Mumbai 28-Jan-11 10:05am    
Very much satisfactory answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900