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