首页 > 代码库 > 生成静态页

生成静态页

namespace Web
{
public partial class StaticPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnOK_Click(object sender, EventArgs e)
{

try
{
//拿到文本框里面的数字
int start = int.Parse(txtStart.Text);
int end = int.Parse(txtEnd.Text);

string path = Request.MapPath("/");
string temp = File.ReadAllText(Request.MapPath("/BookInfoShow.html"));
BookInfoBLL bll = new BookInfoBLL();
for (int i = start; i <= end; i++)
{
string path2 = path + (i / 5000);
if (!Directory.Exists(path2))
{
Directory.CreateDirectory(path2);
}
//根据编号查对象
BookInfo bookInfo = bll.GetOneModel(i);
if (bookInfo == null)
{
return;
}
string path3 = Path.Combine(path2, bookInfo.id + ".html");
string temp2 = temp.Replace("", bookInfo.id.ToString()).Replace("", bookInfo.name.ToString());
File.WriteAllText(path3, temp2);
Label1.Text = "生成成功";
}
}
catch (Exception)
{

Label1.Text = "生成失败";
}

}
}
}

生成静态页