欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp.net實(shí)現(xiàn)生成靜態(tài)頁(yè)并添加鏈接的方法

 更新時(shí)間:2014年07月22日 15:07:33   投稿:shichen2014  
這篇文章主要介紹了asp.net實(shí)現(xiàn)生成靜態(tài)頁(yè)并添加鏈接的方法,非常實(shí)用的功能,需要的朋友可以參考下

本文以實(shí)例講解了asp.net實(shí)現(xiàn)生成靜態(tài)頁(yè)并添加鏈接的方法,非常實(shí)用的功能,通過本實(shí)例可以加深讀者對(duì)于asp.net下文件操作的認(rèn)識(shí)。

1.創(chuàng)建一個(gè)靜態(tài)網(wǎng)頁(yè)模板

<!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>
<title>模板網(wǎng)頁(yè)</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<table $htmlformat[0] height="100%" border="0" width="100%" cellpadding="10" cellspacing="0" gcolor="#eeeeee" style="border:1px solid #000000">
<tr>
<td width="100%" valign="middle" align="left">
<h1>$htmlformat[1]</h1>
<div style="color: $htmlformat[2];font-size: $htmlformat[3]">$htmlformat[4]</div>
</td>
</tr>
</table>
</body>
</html>

2.在asp.net網(wǎng)頁(yè)后臺(tái)代碼中替換模板html頁(yè)中的標(biāo)記符

protected void Button1_Click(object sender, EventArgs e)
{
string[] format = new string[5];//定義和htmlyem標(biāo)記數(shù)目一致的數(shù)組
StringBuilder htmltext = new StringBuilder();
string templatePath = Server.MapPath("~/html/Template.html");
StreamReader sr = new StreamReader(templatePath);
String line;
while ((line = sr.ReadLine()) != null)
{
htmltext.Append(line);
}
sr.Close();
//---------------------給標(biāo)記數(shù)組賦值------------
format[0] = "background=\"bg.jpg\"";//背景圖片
format[1] = TB_Title.Text;
format[2] = "#990099"; //字體顏色
format[3] = "60px";//文字大小
format[4] = TB_Content.Text;
//----------替換htm里的標(biāo)記為你想加的內(nèi)容
for (int i = 0; i < 5; i++)
{
htmltext.Replace("$htmlformat[" + i + "]", format[i]);
}
//----------生成htm文件------------------――
string newfile = Server.MapPath("~/html/"+TB_Title.Text+".html");
StreamWriter sw = new StreamWriter(newfile, false, System.Text.Encoding.GetEncoding("GB2312"));
sw.WriteLine(htmltext);
sw.Flush();
sw.Close();
string newhref="html/" rel="external nofollow" +TB_Title.Text+".html";
Response.Write("<a href=\"" + newhref + "\">" + TB_Title.Text + "</a>");
}

相關(guān)文章

最新評(píng)論