Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI friends i am developing one windows application using C# .

i want to read the content from file and store it in a variable.

the content will be as a path of some other file .

how to read it

thank you
Posted

You can use:

C#
string contents = File.ReadAllText( filepath );


Nick
 
Share this answer
 
At the top of your page you require:
<br />
using System.IO;<br />


Then where you are doing the read you'll require:
<br />
FileStream file = new FileStream("c:\path\to\file.txt", FileMode, FileAccess);<br />
<br />
StreamReader sr = new StreamReader(file);<br />
<br />
string s = sr.ReadToEnd();<br />
<br />
sr.Close();<br />
<br />
file.Close();<br />
<br />


Hope that helps!
 
Share this 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