zoukankan      html  css  js  c++  java
  • .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);

  • 相关阅读:
    练习5.6.3节
    size_t
    练习3.43
    use include to read a file
    ACM数学(转)
    POJ 2039 To and Fro
    poj 1716 差分约束
    poj 3159 差分约束
    hdu 4571 floyd+动态规划
    poj 1364 差分约束
  • 原文地址:https://www.cnblogs.com/zinan/p/3586131.html
Copyright © 2011-2022 走看看