根据模板页面生成页面有感


今天在改公司邮件的时候发现公司的邮件是用模板页面 发现是用模板做的 于是看了看相关的资料 现在对模板粗浅的认识: 模板页面就是写一个静态页面当然如果这个页面是像邮件这样的单独页面的话最好是将样式放到页面中,以免加载该页面的时候出现加载不到的情况,图片最好是用绝对路径。 在这个静态页面中为了让它动态化就将一些内容写成比较特别的方式$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代替成动态的可以了


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值