程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> 創建文章靜態頁面

創建文章靜態頁面

編輯:.NET實例教程

#region 創建靜態頁面(播放頁)
        /// <summary>
        /// 創建靜態頁面(播放頁)
        /// </summary>
        /// <param name="CH_HtmlFileName">靜態頁文件名</param>
        /// <param name="CH_TypeId">欄目ID</param>
        /// <param name="CH_TypeName">欄目名稱</param>
        /// <param name="CH_Title">標題</param>
        /// <param name="CH_AddUsr">發布人</param>
        /// <param name="CH_AddTime">發布時間</param>
        /// <param name="CH_Content_Short">簡介_短</param>
        /// <param name="CH_Content_detail">簡介_長</param>
        /// <param name="CH_KeyWord">關鍵字</param>
        /// <param name="CH_Vid">記錄ID(根據ID更新點擊量)</param>
        /// <param name="CH_Player">播放器</param>
        /// <param name="CH_AboutVideo">相關視頻</param>
        /// <param name="CH_RecommendVideo">推薦視頻</param>
        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);
                }
            &nbsp;   //---------------生成靜態頁----------------//
                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);
     &nbsp;              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------------//
           
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved