设为首页
加入收藏
站内地图
旧版入口
当前位置:首页 > SEO研究 > SEO入门

动态生成Html静态页

作者:佚名 出处:网络转载 时间:09-05 点击:

内容载入中...
  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();
       
      }
      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();
      }


    }
收藏本文:
】【打印页面】【推荐给朋友】【关闭窗口
推荐信息