日期:2014-05-17 浏览次数:20441 次
protected void Button1_Click(object sender, EventArgs e)
{
//在生成新文件之前,删除原来的
System.IO.DirectoryInfo pathd = new System.IO.DirectoryInfo(Server.MapPath("~/html"));//删除html文件夹下文件
deletefile(pathd);
StreamWriter sw = null;
StreamReader sr = null;
string htmlfilename = "";
string str1 = "";
string path1 = HttpContext.Current.Server.MapPath("i.htm");//模板
string path = HttpContext.Current.Server.MapPath("~/html/");//生成文件放在html文件夹下
try
{
sr = new StreamReader(path1, Encoding.GetEncoding("GB2312"));
str1 = sr.ReadToEnd();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sr.Close();
}
try
{
for (int i = 0; i < 4; i++)
{
htmlfilename = ""+ i +".html";
sw = new StreamWriter(path + htmlfilename, false, Encoding.GetEncoding("GB2312"));
str1 = str1.Replace("$i$", i.ToString());
sw.Write(str1);
sw.Flush();
}
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex);
HttpContext.Current.Response.End();
}
finally
{
&n