替换html表内容
public void CreateStaticPage(int bookId)
{
//查询到id
var book = this.DbSession.BooksDal.LoadEntities(c => c.Id==bookId).FirstOrDefault();
//打开html模版文件
var html = HttpContext.Current.Request.MapPath("/Template/BookDetailTemlate.html");
var content = File.ReadAllText(html);
//替换html模版文件的值
content = content.Replace("$title",book.Title).Replace("$author",book.Author)
.Replace("$untiPrice",book.UnitPrice.ToString("0.00")).Replace("$isbn",book.ISBN)
.Replace("$toc",book.TOC).Replace("$content",book.ContentDescription);
string fullDir = "/HtmlPage/" + book.PublishDate.Year + "/" + book.PublishDate.Month +
"/" + book.PublishDate.Day + "/";
//创建文件夹,文件
Directory.CreateDirectory(Path.GetDirectoryName(HttpContext.Current.Request.MapPath(fullDir)));
File.WriteAllText(HttpContext.Current.Request.MapPath(fullDir) + bookId + ".html"
, content, Encoding.UTF8);
}