AdolphYang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 

一键静态化(新闻 ):

 

/// <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);
        }

 

posted on 2015-10-22 12:24  AdolphYang  阅读(246)  评论(0编辑  收藏  举报