Showing posts with label C# read a file. Show all posts
Showing posts with label C# read a file. Show all posts

Monday, July 13, 2015

C#, Read a file

C#, Code to read a file 

String strHtmlMessage = String.Empty;
String strFilePath = HttpContext.Current.Server.MapPath("~/Mails/Confirmationmaill.htm");
  using (StreamReader sr = new StreamReader(strFilePath))
  {
    strHtmlMessage = sr.ReadToEnd();
 }

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();