轨迹鼠的BLOG

人生就像一场旅行,不必在乎目的地,在乎的只是沿途的风景和看风景的心情。

东行记提醒您:您请求的网页正在载入中,请稍后......

公告

东行记提醒您:您请求的网页正在载入中,请稍后......

文章

评论

留言

连接

信息

登陆

搜索

2006-11-4 22:44:46
Asp.net生成静态页面原理

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;

namespace menutest
{
 /// <summary>
 /// Conn 的摘要说明。
 /// </summary>
 // by kyo
 // 此类是生成静态网页的小程序  
 public class Conn
 {
  public Conn()
  {
  
  }
  public static bool WriteFile(string strText,string strContent,string strAuthor)
  {
   string path = HttpContext.Current.Server.MapPath("/menutest/");
   Encoding code = Encoding.GetEncoding("gb2312");
   // 读取模板文件
   string temp = HttpContext.Current.Server.MapPath("/menutest/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";
   string htmlfilename="kyo.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;
  }
 }
}
//原理是利用System.IO中的类读写模板文件,然后用Replace替换掉模板中的标签,写入静态html.


2008-2-28 20:15:02
THX

以下内容含脚本,或可能导致页面不正常的代码

说明:上面显示的是代码内容。您可以先检查过代码没问题,或修改之后再运行。


2008-2-1 12:05:58
link

Fendi Handbag wow gold gucci handbag auto vessel parts WOW Leveling Chanel Handbag Chloe Handbag seo lineage2 adena Silkroad online gold isk TOEFL lineage 2 adena Tactical flashlight golf tee


2008-1-28 12:57:51
link

Fendi Handbag wow gold gucci handbag auto vessel parts WOW Leveling Chanel Handbag Chloe Handbag seo lineage2 adena Silkroad online gold isk TOEFL lineage 2 adena Tactical flashlight golf tee


2008-1-25 13:44:18
Good day

香港注册公司 seo 対策 日语翻译 北京翻译公司 订票 翻译公司 北京翻译 弯管 二手车 丽江 神州租车 青岛网络公司 香港银行开户 订机票 神州汽车租赁 注册香港公司 特价机票 香港公司注册 注册德国公司


2007-12-7 9:42:44
Rate UP

要在城域网上进行教育视频实时直播,检索最新最全的黄石企业信息,以最优惠的价格进行化妆品批发,请访问以上网站,谢谢!


发表评论:

    昵称:
    密码: (游客无须输入密码)
    主页:
    标题:
    东行记提醒您:您请求的网页正在载入中,请稍后......
Powered by Oblog.