根據模板頁面生成頁面有感


今天在改公司郵件的時候發現公司的郵件是用模板頁面 發現是用模板做的 於是看了看相關的資料 現在對模板粗淺的認識: 模板頁面就是寫一個靜態頁面當然如果這個頁面是像郵件這樣的單獨頁面的話最好是將樣式放到頁面中,以免加載該頁面的時候出現加載不到的情況,圖片最好是用絕對路徑。 在這個靜態頁面中爲了讓它動態化就將一些內容寫成比較特別的方式$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代替成動態的可以了


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章