1: XmlDocument xdox = new XmlDocument();
2: xdox.Load(Template); // Load your template here
3: string Subject = xdox.SelectSingleNode("//subject").InnerText;
4: string Body = xdox.SelectSingleNode("//body").InnerText;
5:
6: // Here I will create a dictionary collection that will hold template tags and their values.
7:
8: Dictionary<string, string> Dic = new Dictionary<string, string>();
9:
10: Dic.Add("FirstName", "Farooq");
11: Dic.Add("LastName", "Kaiser");
12: Dic.Add("Description", "Ipod");
13: Dic.Add("OrderNumber", "543535");
14: Dic.Add("Quantity", "1");
15: Dic.Add("Price", "$100");
16: Dic.Add("Total", "$100");
17: Dic.Add("Signature", "Store Manager");
18:
19: // Now, i will use regular expression to replace the values in a template.
20:
21: string HashTagPattern = @"##([A-Za-z0-9]+)##";
22:
23: foreach (Match match in Regex.Matches(Body , HashTagPattern))
24: {
25: if (match.Success)
26: {
27: try
28: {
29: Body = Body.Replace(match.Value, dic[match.Value.Replace("##", "").Trim()]);
30: }
31: catch { }
32: }
33: }