在線客服
24小時(shí)免費(fèi)咨詢電話:18978941786
客服時(shí)間:上午9:30~下午6點(diǎn)
當(dāng)前位置:首頁(yè)>> 技術(shù)文章 >> Web開(kāi)發(fā) >> NET分頁(yè)代碼,生成靜態(tài)頁(yè)面
NET分頁(yè)代碼,生成靜態(tài)頁(yè)面
收藏 分享 發(fā)布日期:2012-2-12 16:30:43 編輯:admin 文章來(lái)源: 點(diǎn)擊率:
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
WriteFile(" 要好好學(xué)啊!! ", "祝你找到一份好工作!!!", "別忘了我", "Jiawenquan.html");
}
public void WriteFile(string strText, string content, string page, string name)
{
string path = HttpContext.Current.Server.MapPath("news/get");
System.Text.Encoding code = System.Text.Encoding.GetEncoding("gb2312");
// 讀取模板文件
string temp = HttpContext.Current.Server.MapPath("news/text.htm");
StreamReader sr = null;
StreamWriter sw = 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();
sr.Close();
}
string htmlfilename = name.ToString();
// 替換內(nèi)容
// 這時(shí),模板文件已經(jīng)讀入到名稱為str的變量中了
str = str.Replace("$title", strText); //模板頁(yè)中的$title,即標(biāo)題
str = str.Replace("$content", content);//模板頁(yè)中的$content,即內(nèi)容
str = str.Replace("$page", page);//模板頁(yè)中的$page,即頁(yè)碼連接格式
// 寫(xiě)文件
try
{
sw = new StreamWriter(path + "/" + htmlfilename, false, code);
sw.Write(str);
sw.Flush();
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
}
} 本文章由南寧網(wǎng)站建設(shè)、南寧網(wǎng)站優(yōu)化、南寧網(wǎng)絡(luò)公司整理,轉(zhuǎn)載請(qǐng)注明出處:http://www.lidajijin.com/