Click here to Skip to main content
15,906,766 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I need to read all the values from a .txt file to a string,
Thanks in advance.
Posted
Comments
[no name] 3-Dec-14 3:11am    
Have you made any effort at all?
Karthik_Mahalingam 3-Dec-14 3:23am    
check this link..

http://msdn.microsoft.com/en-us/library/ezwyzy7b.aspx
Sergey Alexandrovich Kryukov 3-Dec-14 3:28am    
How is that related to "Notepad"? I guess, it is not related...
—SA
Kornfeld Eliyahu Peter 3-Dec-14 4:31am    
Read it carefully it is not-pad... :-)

you can simply do as below
C#
string readText = File.ReadAllText(path);

Read File.ReadAllText Method [^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Dec-14 3:28am    
Yes, a 5.
—SA
DamithSL 3-Dec-14 4:19am    
Thank you, SA
CPallini 3-Dec-14 4:17am    
5.
DamithSL 3-Dec-14 4:19am    
Thank you, CPallini
 
Share this answer
 
Comments
Karthik_Mahalingam 3-Dec-14 3:11am    
:)
Kornfeld Eliyahu Peter 3-Dec-14 3:14am    
It's about the same - low - level as the question... :-)
BillWoodruff 3-Dec-14 3:14am    
My vote of #1: this is not a solution. This is just telling the person asking the question to eff-off.
Kornfeld Eliyahu Peter 3-Dec-14 3:18am    
You are right, but at the very same time (in this case) this is also a full answer...
[no name] 3-Dec-14 3:20am    
I don't think you can argue that. It is a comment and not an answer in the technical sense.
you can use
File.ReadAllLines(filePath);

check out this link
http://msdn.microsoft.com/en-us/library/s2tte0y1%28v=vs.110%29.aspx[^]
 
Share this answer
 
Comments
DamithSL 3-Dec-14 3:25am    
OP asking for file content to a string, not array of string. check solution 3

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