本站首页    管理页面    写新日志    退出

The Neurotic Fishbowl

[学习公共库]ASP.Net生成静态HTML页
麦林 发表于 2007/5/1 15:22:23

环境:Microsoft .NET Framework SDK v1.1 OS:Windows Server 2003 中文版ASP.Net生成静态HTML页在Asp中实现的生成静态页用到的FileSystemObject对象!在.Net中涉及此类操作的是System.IO 以下是程序代码 注:此代码非原创!参考别人代码//生成HTML页 Copy code 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代码-------------------------------------------------------------------------<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML><HEAD>  <title>ShowArticle</title>  <body>biaoti<br>content<br>author</body></HTML>

阅读全文(2438) | 回复(0) | 编辑 | 精华

 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)
 

The Neurotic Fishbowl

.: 公告

fighting for the work!


Bloginess

«December 2025»
123456
78910111213
14151617181920
21222324252627
28293031

.: 我的分类(专题)

首页(449)
文字感悟(103)
学习公共库(61)
生活体会(100)
资源收集(14)
.NET-Winform(27)
音乐文字(15)
心情小记(119)
SQL问题解决(10)


In the Bowl

.: 最新日志

C#打印代码
你看到的我是蓝色的
即将逝去的3月
这个假期
两个月过去
表名存在其他表时获取数据
条码打印
Remoting的用法
INI文件用法


.: 最新回复

回复:条码打印
回复:条码打印
回复:即将逝去的3月
回复:cookie对象使用
回复:条码打印
回复:JSP学习(字符串比较)
回复:应收应付核销规则及常见问题(续)
回复:两个月过去
回复:两个月过去


The Fishkeeper
blog名称:栗色?蓝色?
日志总数:449
评论数量:201
留言数量:37
访问次数:2280247
建立时间:2006年5月16日



Text Me

.: 留言板

签写新留言

链接完成
回:loseVC
来喽~
转转......
新年啦
对自己说
祝福
回:佑手
WO


Other Fish in the Sea

.: 链接


loseVC's BLOG
Collapsar_feel
布衣加针
C#and.Net
Kinogam Web




站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 1.211 second(s), page refreshed 144810371 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号