引用------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();
}
}
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();
}
}
浙公网安备 33010602011771号