设为首页 加入收藏

SEO专栏

当前位置:慧诚博客 >> 网络 >> SEO专栏 >> 浏览文章 >> 动态生成Html静态页

动态生成Html静态页

作者:佚名   来源:网络   点击数:   更新时间:2007年11月03日

public string temp = HttpContext.Current.Server.MapPath("write.htm");
    public Encoding code = Encoding.GetEncoding("gb2312");
    public   StreamReader sr=null;
    public string str="";
   
    public StreamWriter sw=null;
    public string htmlfilename=DateTime.Now.ToString("yyyyMMddHHmmss")+".html";//文件名
    private void Page_Load(object sender, System.EventArgs e)
    {
      try
      {
        sr = new StreamReader(temp, code);
        str = sr.ReadToEnd(); // 读取文件
      }
      catch(Exception exp)
      {
        HttpContext.Current.Response.Write(exp.Message);
        HttpContext.Current.Response.End();
       
      }
      finally
      {
        sr.Close();
      }
      //-------------------------------------------------------------------
      //-------------------------------------------------------------------
      //-------------------------------------------------------------------
      try
      {
        sw = new StreamWriter(Server.MapPath(htmlfilename) , false, code);
        str = str.Replace("aa","chi");//文本替代

        sw.Write(str);
        sw.Flush();
      }
      catch(Exception ex)
      {
        HttpContext.Current.Response.Write(ex.Message);
        HttpContext.Current.Response.End();
      }
      finally
      {
        sw.Close();
      }


    }


-------------------------
引用------using System.IO;//必用到的命名空间-

 
2005-04-12


动态生成Html静态页

public string temp = HttpContext.Current.Server.MapPath("write.htm");
    public Encoding code = Encoding.GetEncoding("gb2312");
    public   StreamReader sr=null;
    public string str="";
   
    public StreamWriter sw=null;
    public string htmlfilename=DateTime.Now.ToString("yyyyMMddHHmmss")+".html";//文件名
    private void Page_Load(object sender, System.EventArgs e)
    {
      try
      {
        sr = new StreamReader(temp, code);
        str = sr.ReadToEnd(); // 读取文件
      }
      catch(Exception exp)
      {
        HttpContext.Current.Response.Write(exp.Message);
        HttpContext.Current.Response.End();
       
      }

下一页
本文共 2 页,第  [1]  [2]  页


推荐文章
热门文章