EMail Template from flat file or notepad in ASP.NET with C#.NET


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 ASP.NET
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
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.
Share this post :

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.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar