创建文章静态页面

 

#region 创建静态页面(播放页)
        ///


        /// 创建静态页面(播放页)
        ///

        /// 静态页文件名
        /// 栏目ID
        /// 栏目名称
        /// 标题
        /// 发布人
        /// 发布时间
        /// 简介_短
        /// 简介_长
        /// 关键字
        /// 记录ID(根据ID更新点击量)
        /// 播放器
        /// 相关视频
        /// 推荐视频
        public void CreateHtmlShowPage(string CH_HtmlFileName, string CH_TypeId, string CH_TypeName, string CH_Title, string CH_AddUsr, string CH_AddTime, string CH_Content_Short, string CH_Content_detail, string CH_KeyWord, string CH_Vid, string CH_Player, string CH_AboutVideo, string CH_RecommendVideo)
        {
            StringBuilder s = new StringBuilder();
            string line = string.Empty;
            //模板文件内容
            string TemplateContent = string.Empty;
            //模板文件路径
            string TemplateFilePath = System.Web.HttpContext.Current.Server.MapPath("/Video/Template/Tmp_VideoShow.htm");
            //静态页存放的文件夹路径
            string HtmlFolderPath = System.Web.HttpContext.Current.Server.MapPath("/Video/Html/");
            //静态页文件路径
            string HtmlFilePath = HtmlFolderPath + CH_HtmlFileName;
            try
            {
                //--------------读取模板中的内容--------------//
                using (StreamReader sr = new StreamReader(TemplateFilePath, System.Text.Encoding.GetEncoding("utf-8")))
                {
                    while ((line = sr.ReadLine()) != null)
                    {
                        s.AppendLine(line);
                        //s.AppendLine("/n");
                    }
                    sr.Close();
                }
                TemplateContent = s.ToString();
                //-------判断静态页文件夹路径是否存在--------//
                if (!Directory.Exists(HtmlFolderPath))
                {
                    Directory.CreateDirectory(HtmlFolderPath);
                }
                //---------------生成静态页----------------//
                using (StreamWriter sw = new StreamWriter(HtmlFilePath, false, System.Text.Encoding.GetEncoding("utf-8")))
                {
                    TemplateContent = TemplateContent.Replace("$HtmlFormat[TypeName]", CH_TypeName);
                    TemplateContent = TemplateContent.Replace("$HtmlFormat[TypeId]", CH_TypeId);
                    TemplateContent = TemplateContent.Replace("$HtmlFormat[Title]", CH_Title);
                    TemplateContent = TemplateContent.Replace("$HtmlFormat[AddUsr]", CH_AddUsr);
                    TemplateContent = TemplateContent.Replace("$HtmlFormat[AddTime]", CH_AddTime);
                    TemplateContent = TemplateContent.Replace("$HtmlFormat[Content_Short]", CH_Content_Short);
                    TemplateContent = TemplateContent.Replace("$HtmlFormat[Content_detail]", CH_Content_detail);
                    TemplateContent = TemplateContent.Replace("$HtmlFormat[KeyWord]", CH_KeyWord);
                    TemplateContent = TemplateContent.Replace("$HtmlFormat[Vid]", CH_Vid);
                    TemplateContent = TemplateContent.Replace("$HtmlFormat[Player]", CH_Player);
                    TemplateContent = TemplateContent.Replace("$HtmlFormat[AboutVideo]", CH_AboutVideo);
                    TemplateContent = TemplateContent.Replace("$HtmlFormat[RecommendVideo]", CH_RecommendVideo);
                    sw.WriteLine(TemplateContent);
                    sw.Close();
                }
                //----------------------END------------//
            }
            catch (Exception ex)
            {
                throw new Exception("BLL.AudiovisualBLL.CreateHtmlShowPage:" + ex.Message);
            }
        }
        #endregion

你可能感兴趣的:(创建文章静态页面)