All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
PHP中用正则表达式验证中文的问题_php资料_编程技术
去掉ul全局配置及smarty的问题_php资料_编程技术
Linux操作系统启动httpd失败的解决方法_php资料_编程技术
动态控件添加终极解决方案_[Asp.Net教程]
.NET内置对象之Response对象_[Asp.Net教程]
PHP操作XML做数据库的类_[PHP教程]
九 表格 Tables_[Html教程]
ASP.NET2.0中Gridview的使用技巧_[Asp.Net教程]
学习PHP小结:PHP编程中常用的三则技巧_[PHP教程]
PHP代码:得到客户端的IP_php资料_编程技术
Reading number is top 10 pictures
Look for from human art net, is good1
29 the belle stars after bath figure2
Sora aoi possession of boudoir1
西方气质的东方美女1
中国的阶级现状
The most popular girls welcome eggplant
南昌铁路局宜春车务段攸县车站铁路职工福利房被开发商侵占
一千块钱如何创业
美女就是美女
Poor doll, hand job was caught the currently in effect by his dad
Download software ranking
Prostitutes diary
Eclipse 4.2.1 For Win32
Boxer's Top ten classic battle9
Eclipse 4.2.2 For Win64
双旗镇刀客A
美女写真2
Unix video tutorial1
Tram sex maniac 2 (H) rar bag19
The king of fighters 97(Mobile phone games-apk)
C#与.NET技术平台实战演练
aaa published in(发表于) 2013/12/13 9:40:29 Edit(编辑)
ASP.NET技巧:利用模版生成html页_.net资料_编程技术

ASP.NET技巧:利用模版生成html页_.net资料_编程技术

ASP.NET技巧:利用模版生成html页_.net资料_编程技术-你的首页-uuhomepage.com

Asp.NET 生成静态页


环境:Microsoft .NET Framework SDK v1.1
OS:Windows Server 2003 中文版
ASP.Net生成静态HTML页
在Asp中实现的生成静态页用到的FileSystemObject对象!
在.Net中涉及此类操作的是System.IO
以下是程序代码 注:此代码非原创!参考别人代码



//生成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";
// 替换内容
// 这时,模板文件已经读入到名称为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;


此函数放在Conn.CS基类中了
在添加新闻的代码中引用 注:工程名为Hover


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


模板页Text.html代码





ShowArticle

biaoti


content

author


biaoti


content

author






添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.