一键静态化(新闻 ):
/// <summary> /// 一键 新闻静态化 /// </summary> /// <param name="list">新闻集合</param> /// <param name="cshtmlVirtualPath">新闻实例的虚拟路径</param> public static void NewsesStatic(List<object> list,string cshtmlVirtualPath) { foreach(object obj in list) { TD_NEWS news = obj as TD_NEWS; NewsStatic(news, cshtmlVirtualPath); } } /// <summary> /// 新闻静态化 /// </summary> /// <param name="news">新闻实例</param> /// <param name="cshtmlVirtualPath">新闻实例的虚拟路径</param> private static void NewsStatic(TD_NEWS news,string cshtmlVirtualPath) { string html = RazorHelper.RazorParseHtml(HttpContext.Current, cshtmlVirtualPath, new { title = news.TITLE, content = news.CONTENT, createDate = news.CREATEDATE }); string pathPre = ConfigurationManager.AppSettings["ViewStaticDirecPre"]; string path = pathPre + news.CATEGORYID + "\\" + news.ID + ".shtml"; //文件全路径 string pathName = Path.GetDirectoryName(path); if(!Directory.Exists(pathName)) { Directory.CreateDirectory(pathName); } File.WriteAllText(path, html); }
时间: 2024-10-12 16:09:45