.net简单的静态页生成

 

1.得到实体对象model,读取模板

string htmlMaster = File.ReadAllText(HttpContext.Current.Server.MapPath("/master/bookDetaile.htm"));
2.然后替换占位符
string repHtml = htmlMaster.Replace("$title", model.Title).Replace("$coverImage", "/Images/BookCovers/" + model.ISBN + ".jpg").Replace("$Author", model.Author).Replace("$bookDes", model.AurhorDescription).Replace("$bookPrice", model.UnitPrice.ToString()).Replace("$bookPublishDate", model.PublishDate.ToString()).Replace("$bookId", model.Id.ToString());

3.设定保存路径,注意命名规则
string path =HttpContext.Current.Server.MapPath(string.Format("/AutoCreatStaticPage/{0}/{1}/{2}/{3}.html", model.PublishDate.Year.ToString(), model.PublishDate.Month.ToString(), model.PublishDate.Day.ToString(),model.Id));
4.创建文件夹
Directory.CreateDirectory(Path.GetDirectoryName(path));
5.将字符串保存到磁盘
File.WriteAllText(path, repHtml,Encoding.UTF8);

.net简单的静态页生成,布布扣,bubuko.com

.net简单的静态页生成

上一篇:Molecule – 帮助你构建跨平台的 HTML5 游戏


下一篇:适用于Firemonkey的Json解析对象XsuperObject使用方法介绍