注册 登陆 资料 在线 排行 帖子 文件 查询 收件箱 风格

加入收藏 

使用帮助 

 
首页 >> 建站知识库 >> 搜索引擎优化与网络推广 >> 『 Google搜索引擎优化 』 >> 动态生成Html静态页
 新帖 新投票 讨论区 精华区 上篇 刷新 平板 下篇  


 帖子主题: 动态生成Html静态页
离线

xuefengf 



职务:论坛版主
级别:骑士
积分:193
经验:379
文章:183
注册:06-04-21 11:47

发表: 2006-11-14 20:31:53 人气:15357

动态生成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();
      }


    }


-------------------------
引用------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();
      }


    }


-----------------------------------------------------
伊路网络,做最专业的外贸网站
大量客户成功案例(点击查看):
http://www.elut.cn/works.html


-----------------------------------------------------
相关帖子
动态生成Html静态页 (xuefengf,15357,2006-11-14 20:31:53)



回复帖子 注意: *为必填项
*用户名
(没有注册的点击这里注册新用户)
*密码
*帖子名称
最长255字
表情
插入UBB标签

内容(最大16K)

是否是UBB代码

内容支持插入UBB标签,使用方法请参考帮助

按Ctrl+Enter快速提交


插入表情,时间   T 长度
 其它选项:  显示签名   不允许回复  - UBB标签  - 颜色表