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

Reading number is top 10 articles
sqlserver,存储过程例子_mssql学习_编程技术
构成Delphi工程的文件:资源文件(.res)
计算两者相差几个月零几天_[PHP教程]
php下js效果调用右侧小图左侧放大显示_php资料_编程技术
详细阐述PHP环境下如何将gbk编码转成utf8格式_[PHP教程]
动态网页技术PHP程序中包含文件问题_php资料_编程技术
利用ASP.NET,2.0客户端callbacks限制postbacks_[Asp.Net教程]
使用ASP.NET制作功能完善的安装程序_.net资料_编程技术
用C#实现pdf文件的完整性验证_[Asp.Net教程]
用PHP生成自己的LOG文件_[PHP教程]
Reading number is top 10 pictures
The world's ten biggest attractions of inventory super the moon
Fan bingbing black wings for platform and DanLuoWang believes beauty1
Ashlynn Brooke show proud chest measurement2
超强高考作文
30 beautiful school beauty2
Born After 90 Beijing sports university campus flower photos3
So beauty, will let you spray blood1
初吻给了谁?
大人物的礼物
美女当网吧管理员的悲剧
Download software ranking
美女写真2
Be there or be square
Boxer Classic video2
功夫熊猫2(上集)
Tram sex maniac 2 (H) rar bag6
Ashlynn Video2
Adobe Flash Player(IE) 10.0.32.18 浏览器专用的FLASH插件
中国结婚习俗实录
Unix video tutorial7
WebService在.NET中的实战应用教学视频 → 第5集
delv published in(发表于) 2014/1/23 2:48:20 Edit(编辑)
.net利用模版生成html页_[Asp.Net教程]

.net利用模版生成html页_[Asp.Net教程]

.net利用模版生成html页_[Asp.Net教程]

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.