 |


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

 xuefengf | 

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

 |
发表: 2006-11-14 20:31:53 人气:15346 
动态生成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(); }
}
-----------------------------------------------------| 相关帖子 | |
动态生成Html静态页 (xuefengf,15346,2006-11-14 20:31:53) |
|
|

 回复帖子 注意: *为必填项 |
|
|
|
Copyright © 2018 外贸网站建设,SOHO英文网页制作,网站设计公司--伊路网络工作室 版权所有
本论坛内容纯属发表个人意见,与雪风伊路网络科技立场无关
论坛域名:bbs.elut.cn
页面执行时间:56毫秒