最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

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

<!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)頁</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)頁后臺(tái)代碼中替換模板html頁中的標(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)論

绥中县| 板桥市| 九台市| 闸北区| 友谊县| 武冈市| 达拉特旗| 大冶市| 云龙县| 古交市| 灵武市| 延边| 论坛| 阳江市| 上犹县| 新蔡县| 云南省| 东兴市| 聊城市| 大洼县| 化州市| 鄂托克旗| 景宁| 常宁市| 安阳市| 河北区| 鱼台县| 承德市| 黄梅县| 东海县| 甘南县| 盘山县| 高安市| 堆龙德庆县| 临朐县| 云浮市| 庆阳市| 海门市| 高唐县| 习水县| 丰台区|