日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

ASP.NET生成靜態(tài)網(wǎng)頁的方法_.Net教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:如何以及為何創(chuàng)建Search .NET版
Search 開發(fā)負(fù)責(zé)人 Larry Jordan、開發(fā)人員 Michael Ruggiero 和 Michael Stanton 以及 .NET 框架項(xiàng)目經(jīng)理 Hari Sekhar 在暗中構(gòu)建了基于 .NET 技術(shù)的 Microsoft Web 站點(diǎn)搜索引擎新版

環(huán)境:Microsoft .NET Framework SDK v1.1

OS:Windows Server 2003 中文版

ASP.Net生成靜態(tài)HTML頁,在Asp中實(shí)現(xiàn)的生成靜態(tài)頁用到的FileSystemObject對(duì)象,在.Net中涉及此類操作的是System.IO

注:以下是參考別人的程序代碼,非原創(chuàng)!

Code:

以下為引用的內(nèi)容:
/生成HTML頁
public static bool WriteFile(string strText,string strContent,string strAuthor)
{
string path = HttpContext.Current.Server.MapPath("/news/");
Encoding code = Encoding.GetEncoding("gb2312");
// 讀取模板文件
string temp = HttpContext.Current.Server.MapPath("/news/text.html");
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=DateTime.Now.ToString("yyyyMMddHHmmss") ".html";
// 替換內(nèi)容
// 這時(shí),模板文件已經(jīng)讀入到名稱為str的變量中了
str =str.Replace("ShowArticle",strText); //模板頁中的ShowArticle
str = str.Replace("biaoti",strText);
str = str.Replace("content",strContent);
str = str.Replace("author",strAuthor);
// 寫文件
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();
}
return true;

此函數(shù)放在Conn.CS基類中了
在添加新聞的代碼中引用 注:工程名為Hover

if(Hover.Conn.WriteFilethis.Title.Text.ToString),this.Content.Text.ToString),this.Author.Text.ToString)))
{
Response.Write("添加成功");
}
else
{
Response.Write("生成HTML出錯(cuò)!");
}

模板頁Text.html代碼

Code:

以下為引用的內(nèi)容:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>ShowArticle</title>
<body>
biaoti
<br>
content<br>
author
</body>
</HTML>
biaoti
<br>
content<br>
author
</body>
</HTML>

提示添加成功后會(huì)出以當(dāng)前時(shí)間為文件名的html文件!上面只是把傳遞過來的幾個(gè)參數(shù)直接寫入了HTML文件中,在實(shí)際應(yīng)用中需要先添加數(shù)據(jù)庫,然后再寫入HTML文件

請(qǐng)作者聯(lián)系本站,及時(shí)附注您的姓名。聯(lián)系郵箱:mb5u#vip.qq.com(把#改為@)。

分享:ASP.NET網(wǎng)絡(luò)編程中常用到的27個(gè)函數(shù)集
1、DateTime 數(shù)字型 以下為引用的內(nèi)容: System.DateTime currentTime=new System.DateTime(); 1.1 取當(dāng)前年月日時(shí)分秒 currentTime=System.DateTime.

來源:模板無憂//所屬分類:.Net教程/更新時(shí)間:2008-08-22
相關(guān).Net教程