今天在改公司邮件的时候发现公司的邮件是用模板页面 发现是用模板做的 于是看了看相关的资料 现在对模板粗浅的认识: 模板页面就是写一个静态页面当然如果这个页面是像邮件这样的单独页面的话最好是将样式放到页面中,以免加载该页面的时候出现加载不到的情况,图片最好是用绝对路径。 在这个静态页面中为了让它动态化就将一些内容写成比较特别的方式$UserName 或者是#UserName 的方式都是可以的。好了这样模板页面就算是好了,就像:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>
</title>
<link href="http://www.cnblogs.com/2011_08_24/lucklist/template.css" rel="stylesheet" type="text/css" /></head>
<body class="template_body" style="margin: 0 auto 0 auto;background-image: url(../images/bg_03.jpg);width:406px;">
<table border="0" cellpadding="0" cellspacing="0" style="text-align: left;">
<tr style="background-image: URL(../images/bg_04.jpg);height: 24px">
<td class="tdName">#Name</td>
<td class="tdTime">#Time</td>
<td class="tdLuckName">#LuckName</td>
</tr>
<tr style="background-image: URL(../images/bg_04.jpg);height: 24px">
<td class="tdName">#Name</td><td class="tdTime">#Time</td><td class="tdLuckName">#LuckName</td></tr>
</table><div class="Page">#Page</div></body></html>
就像上面的情况
那怎样让他动态的呢 方法是:将该静态页面读出:
方法:
/// <summary> /// 读取HTML文件 /// </summary>
/// <param name="temp">HttpContext.Current.Server.MapPath("./lucklist/Main.html");</param>/// <returns></returns>
public string ReadHtmlFile(string temp)
{
StreamReader sr = null;
string str = "";
try
{
sr = new StreamReader(temp, code);
str = sr.ReadToEnd(); // 读取文件 }
catch (Exception exp)
{
HttpContext.Current.Response.Write(exp.Message);
HttpContext.Current.Response.End(); }
finally
{
sr.Dispose();
sr.Close();
}
return str;
}
接下来就简单了:
将">#LuckName代替成动态的可以了