Skip to main content

Posts

Showing posts with the label C# read a file

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

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