protected void Button1_Click(object sender, EventArgs e)
{
string mbPath = Server.MapPath("template.htm");
Encoding code = Encoding.GetEncoding("gb2312");
StreamReader sr = null;
StreamWriter sw = null;
string str = null;
try
{
sr = new StreamReader(mbPath, code);
str = sr.ReadToEnd();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sr.Close();
}
string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";
str = str.Replace("$title$", this.txtTitle.Text);
str = str.Replace("$content$", this.txtContent.Text);
try
{
sw = new StreamWriter("M:\\" + fileName, false, code);
sw.Write(str);
sw.Flush();
}
catch (Exception ee)
{
throw ee;
}
finally
{
sw.Close();
Response.Write("<a href=M:\\" + fileName + " target=_blank>" + fileName + "</a>已经生成,保存在htm文件夹下!");
}
}