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

Reading number is top 10 articles
C#程序中的DirectShow设计
在C#中使用.chm帮助文件
visual c++ 中CFontDialog对话框实例
。net中前台javascript与后台c#相互调用
asp.net页面导出为Word文档_[Asp.Net教程]
初学者全面接触javascript的基本数据结构_JavaScript技术_编程技术
asp.net2.0服务器控件之Label控件
SQL,Server处理数据层错误_[SQL,Server教程]
SQL Server数据库恢复操作实例_[SQL Server教程]
基于AJAX技术提高搜索引擎排名_[AJAX教程]
Reading number is top 10 pictures
西游四格漫画(五)
Cesarean section, bloody, silently into it!1
Forced sex girl living abroad2
LiXiang early youth photo
梦幻的风景
9.3阅兵全景图7-指挥系统和后勤保障系统梯队
Household design of gorgeous series
重口味人造肉
Summer is most suitable for young people to travel in China6
2012 national geographic daily picture3
Download software ranking
Eclipse 4.2.2 For Win64
电脑知识及技巧大合集
功夫熊猫2(下集)
Take off clothes to survival
WebService在.NET中的实战应用教学视频 → 第1集
Be there or be square
Call Of Duty5
C#与.NET技术平台实战演练
Unix video tutorial11
Unix video tutorial1
aaa published in(发表于) 2013/12/6 10:25:28 Edit(编辑)
asp.net生成静态页面_.net资料_编程技术

asp.net生成静态页面_.net资料_编程技术

asp.net生成静态页面_.net资料_编程技术-数科优化网

//生成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代码



CODE:



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.