首页 > Web开发 > 详细

.net简单的静态页生成

时间:2014-03-09 12:44:22      阅读:564      评论:0      收藏:0      [点我收藏+]

 

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简单的静态页生成

原文:http://www.cnblogs.com/zinan/p/3586131.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!