Based on your comments, it looks like you're trying to generate a html file to be sent via email. Your better off creating a html file with place holders
for the information you want to inject. Use a text reader to read the html from the file, and use regex or string.replace on the text replacing the place holders
for the actual values.
You will need to have a full URL to images.
e.g.
To read the HTML
var HTML = EmailTemplate.GetHTMLFromTemplate(path to template)
public static string GetHTMLFromTemplate(string templatepath)
{
var TemplateBody = new StringBuilder();
using (var Reader = new StreamReader(templatepath))
{
string Line;
while ((Line = Reader.ReadLine()) != null)
{
TemplateBody.Append(Line);
}
}
return TemplateBody.ToString();
}
Then replace the parts of the html
String.Replace("[image placeholder]", ConfigurationManager.AppSettings["Image"]);
The Email Template class looks like this (this is very old code!!)
public class EmailTemplate
{
public string Body { get; private set; }
public static EmailTemplate GetTemplate(string body, string url, string html)
{
var AmendedHTML = new StringBuilder(html);
AmendedHTML.Replace("[body]", body);
AmendedHTML.Replace("../images", url + "images");
var MyEmailTemplate = new EmailTemplate { Body = AmendedHTML.ToString() };
return MyEmailTemplate;
}
public static EmailTemplate GetTemplate(string body, string title, string url, string year, string html)
{
var AmendedHTML = new StringBuilder(html);
AmendedHTML.Replace("[BODY]", body);
AmendedHTML.Replace("[HEADING]", title);
AmendedHTML.Replace("../images", url + "images");
AmendedHTML.Replace("[DATE]", year);
AmendedHTML.Replace("[contactus.aspx]", url + "contactus/index.aspx");
AmendedHTML.Replace("[unsubscribe.aspx]", url + "register/unsubscribe.aspx");
var MyEmailTemplate = new EmailTemplate { Body = AmendedHTML.ToString() };
return MyEmailTemplate;
}
public static string GetHTMLFromTemplate(string path)
{
var TemplateBody = new StringBuilder();
using (var Reader = new StreamReader(path))
{
string Line;
while ((Line = Reader.ReadLine()) != null)
{
TemplateBody.Append(Line);
}
}
return TemplateBody.ToString();
}
}