示例#1
0
        /// <summary>
        /// 获取HTML文件,如果不存在,则动态生成HTML文件,并判断文件有效时间,过期则重新生成
        /// </summary>
        /// <param name="mPage"></param>
        /// <param name="AspxFile"></param>
        /// <param name="HtmlFile"></param>
        /// <param name="Hour"></param>
        /// <returns></returns>
        public static string GetPageHtml(System.Web.UI.Page mPage, string AspxFile, string HtmlFile, int Hour)
        {
            string strContent = "";
            string file       = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "/" + HtmlFile;

            if (File.Exists(file) == false)
            {
                StringWriter sw = new StringWriter();
                mPage.Server.Execute(AspxFile, sw);
                strContent = sw.ToString();
                CFile.CreateFile(HtmlFile, strContent);
            }
            else
            {
                if (CFile.IsFileExpired(file, Hour) == false)
                {
                    strContent = CFile.GetFileContent(HtmlFile);
                }
                else
                {
                    StringWriter sw = new StringWriter();
                    mPage.Server.Execute(AspxFile, sw);
                    strContent = sw.ToString();
                    CFile.CreateFile(HtmlFile, strContent);
                }
            }

            return(strContent);
        }