In most of the applications, we will use templates for sending emails, updating pages and etc. As part of that, in this post i have explained how to open text file using c#.net. After that we will replacing template string with the exact values.
Text file contains:
EMail Template in C#.NET |
class Program { static void Main(string[] args) { string strFilePath = @"D:\.net practise\ReadDataFromFlatFile\ReadDataFromFlatFile\EMailBody.txt"; string fileContent = string.Empty; FileStream fs = new FileStream(strFilePath, FileMode.Open,FileAccess.Read); StreamReader sr = new StreamReader(fs); fileContent = sr.ReadToEnd(); sr.Close(); fileContent=GetContent(fileContent); Console.WriteLine(fileContent); Console.ReadLine(); } public static string GetContent(string fileContent) { fileContent = fileContent.Replace("<@CustomerName@>", "Ranga Rajesh Kumar"); fileContent = fileContent.Replace("<@AdminName@>", "http://aspnettutorialonline.blogspot.com"); return fileContent; } }
Output:
EMail Template from flat file or notepad in ASP.NET with C#.NET |
If you have any queries or suggestions, please feel free to ask in comments section.
Post a Comment
Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.