asp.net實(shí)現(xiàn)生成靜態(tài)頁(yè)并添加鏈接的方法
本文以實(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>"); }
- asp.net中MVC借助Iframe實(shí)現(xiàn)無刷新上傳文件實(shí)例
- asp.net在iframe中彈出信息并執(zhí)行跳轉(zhuǎn)問題探討
- ASP.NET頁(yè)面借助IFrame提交表單數(shù)據(jù)所遇到問題的解決方法分享
- asp.net 文件上傳與刷新與asp.net頁(yè)面與iframe之間的數(shù)據(jù)傳輸
- ASP.NET中使用IFRAME建立類Modal窗口
- asp.net省市三級(jí)聯(lián)動(dòng)的DropDownList+Ajax的三種框架(aspnet/Jquery/ExtJs)示例
- asp.net 學(xué)習(xí)之路 項(xiàng)目整體框架簡(jiǎn)單的搭建
- asp.net GridView中超鏈接的使用(帶參數(shù))
- ASP.NET 鏈接 Access 數(shù)據(jù)庫(kù)路徑問題最終解決方案
- ASP.NET中iframe框架點(diǎn)擊左邊頁(yè)面鏈接 右邊顯示鏈接頁(yè)面內(nèi)容
相關(guān)文章
asp.net Oracle數(shù)據(jù)庫(kù)訪問操作類
asp.net Oracle數(shù)據(jù)庫(kù)訪問操作類,需要的朋友可以參考一下2013-03-03asp.net在事件中啟動(dòng)線程來打開一個(gè)頁(yè)面的實(shí)現(xiàn)方法
點(diǎn)擊一個(gè)按鈕做兩件事情,一件需要點(diǎn)擊按鈕馬上完成,另一件事情是點(diǎn)擊按鈕后做其他事情,不會(huì)的朋友一起來看看下面是如何實(shí)現(xiàn)的2014-11-11在ASP.NET2.0中通過Gmail發(fā)送郵件的代碼
我們有時(shí)候需要發(fā)送郵件給訪問網(wǎng)頁(yè)的用戶,例如,注冊(cè)的時(shí)候,發(fā)一確認(rèn)信什么的。那么,在ASP.NET2.0中該如果操作呢?2008-06-06ASP.NET Core依賴注入DI容器的方法實(shí)現(xiàn)
本文主要介紹了ASP.NET Core依賴注入DI容器的方法實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03ASP.NET用DataSet導(dǎo)出到Excel的方法
ASP.NET用DataSet導(dǎo)出到Excel的方法,需要的朋友可以參考一下2013-03-03asp.net 讀取并修改config文件實(shí)現(xiàn)代碼
讀取并修改 config 文件的asp.net代碼,方便我們用asp.net修改配置文件。2009-11-11asp.net 使用Silverlight操作ASPNETDB數(shù)據(jù)庫(kù)
asp.net下使用Silverlight操作ASPNETDB數(shù)據(jù)庫(kù)的實(shí)現(xiàn)代碼2010-01-01