Wednesday, October 6, 2010

Read a File

1. Map The Server Path
string strFileName = Server.MapPath("partnership_msg.txt");

2. Here is the code to Read Text File From Path "partnership_msg.txt" into streamReader
StreamReader sr = new StreamReader(new FileStream(strFileName,FileMode.Open, FileAccess.Read));

3. Read the content from the StreamReader into string variable
strBody = sr.ReadToEnd();

4. Close the Streamreader
sr.Close();

No comments: