设置首页  |   加入收藏  |  联系我们   
您的位置: 主页>网络应用>搜索引擎优化>正文
动态生成Html静态页
文章来源:Linuxdby.com  编辑:  发布时间:2007-11-19

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


}

 
Tags:静态 生成 动态 public str // code string //-----------------------
Google
 
上一篇: SEO研究-从管理学看 SEO 和 SEF 之 5W1H   下一篇: 原创-利用百度产品进行百度优化
【返回顶部】 【打印】 【大】 【中】 【小】 【关闭】

 我来说两句
用户名: 新注册) 密码: 匿名评论 [论坛讨论]
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 相关文章
 热门文章

 
版权所有  2005-2006  Linux集中营  闽ICP备07500055号