茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    asp.net基于替換模版頁的形式生成靜態(tài)頁的方法
    來源:易賢網(wǎng) 閱讀:1047 次 日期:2016-08-05 15:27:30
    溫馨提示:易賢網(wǎng)小編為您整理了“asp.net基于替換模版頁的形式生成靜態(tài)頁的方法”,方便廣大網(wǎng)友查閱!

    本文實例講述了asp.net基于替換模版頁的形式生成靜態(tài)頁的方法。分享給大家供大家參考,具體如下:

    第一步:新建項目,創(chuàng)建一個簡單模版頁:TemplatePage.htm

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

      <title>Porschev 生成靜態(tài)頁簡單示例</title>

    </head>

    <body>

    <h1>$Porschev[0]$</h1>

    <ul>

    <li>頁標題:$Porschev[0]$</li>

    <li>名稱:$Porschev[1]$</li>

    <li>網(wǎng)址:<a href="$Porschev[2]$" target="_blank">$Porschev[2]$</a></li>

    <li>時間:$Porschev[3]$</li>

    <li>詳述:$Porschev[4]$</li>

    </ul>

    </body>

    </html>

    第二步:創(chuàng)建一個config文件:CreateHtml.config

    <?xml version="1.0" encoding="utf-8" ?>

    <web>

     <website key="0" value="title"/>

     <website key="1" value="name"/>

     <website key="2" value="url"/>

     <website key="3" value="createDate"/>

     <website key="4" value="desc"/>

    </web>

    第三步:編寫生成靜態(tài)頁代碼:(添加System.Web引用)

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.IO;

    using System.Xml;

    namespace CreateHtmlBLL

    {

      public class CreateHtmlBLL

      {

        #region##讀取配置文件某節(jié)點的個數(shù)

        ///<summary>

        /// 讀取配置文件某節(jié)點的個數(shù)

        ///</summary>

        ///<param name="path">配置文件的路徑</param>

        ///<param name="nodeName">要獲取的節(jié)點</param>

        ///<returns>返回節(jié)點個數(shù)</returns>

        private int ReadConfig(string path,string nodeName)

        {

          string absoPath = string.Empty; //絕對路徑

          try

          {

            absoPath = System.Web.HttpContext.Current.Server.MapPath(path);

            XmlDocument xd = new XmlDocument();

            xd.Load(absoPath);

            XmlNodeList nodeList = xd.SelectNodes(nodeName); //得到相應(yīng)節(jié)點的集合

            return nodeList.Count;

          }

          catch (Exception)

          {

            throw;

          }

        }

        #endregion

        #region##創(chuàng)建文件夾

        ///<summary>

        /// 創(chuàng)建文件夾

        ///</summary>

        ///<param name="path">要創(chuàng)建的路徑</param>

        public void CreatFolder(string path)

        {

          string absoPath = string.Empty; //絕對路徑

          try

          {

            absoPath = System.Web.HttpContext.Current.Server.MapPath(path);

            if (!Directory.Exists(absoPath))

            {

              Directory.CreateDirectory(absoPath);

            }

          }

          catch (Exception)

          {

            throw;

          }

        }

        #endregion

        #region##生成HTML頁

        ///<summary>

        /// 生成HTML頁

        ///</summary>

        ///<param name="configPath">配置文件的路徑</param>

        ///<param name="configNodeName">配置文件節(jié)點名</param>

        ///<param name="temPath">模版頁路徑</param>

        ///<param name="arr">替換數(shù)組</param>

        ///<param name="createPath">生成HTML路徑</param>

        public void CreateHtml(string configPath, String configNodeName, string temPath, string[] arr,string createPath)

        {

          string fileName = string.Empty;     //生成文件名

          string absoCrePath = string.Empty;   //生成頁絕對路徑

          string absoTemPath = string.Empty;   //模版頁的絕對中徑

          int nodeCount = 0;           //節(jié)點數(shù)

          try

          {

            absoCrePath = System.Web.HttpContext.Current.Server.MapPath(createPath);

            absoTemPath = System.Web.HttpContext.Current.Server.MapPath(temPath);

            nodeCount = ReadConfig(configPath, configNodeName);

            FileStream fs = File.Open(absoTemPath, FileMode.Open, FileAccess.Read); //讀取模版頁

            StreamReader sr = new StreamReader(fs, Encoding.GetEncoding("utf-8"));

            StringBuilder sb = new StringBuilder(sr.ReadToEnd());

            sr.Close();

            sr.Dispose();

            for (int i = 0; i < nodeCount; i++)

            {

              sb.Replace("$Porschev[" + i + "]$", arr[i]);

            }

            CreatFolder(createPath);

            fileName = DateTime.Now.ToFileTime().ToString() + ".html";     //設(shè)置文件名(這里可以根據(jù)需要變化命名)

            FileStream cfs = File.Create(absoCrePath + "/" + fileName);

            StreamWriter sw = new StreamWriter(cfs, Encoding.GetEncoding("utf-8"));

            sw.Write(sb.ToString());

            sw.Flush();

            sw.Close();

            sw.Dispose();

          }

          catch (Exception)

          {

            throw;

          }

        }

        #endregion

      }

    }

    第四步:測式生成

    protected void Page_Load(object sender, EventArgs e)

    {

        CreateHtml();

    }

    #region##生成靜態(tài)頁

    ///<summary>

    /// 生成靜態(tài)頁

    ///</summary>

    public void CreateHtml()

    {

        try

        {

          string[] arr = new string[5];

          arr[0] = "Porschev 靜態(tài)頁測式";

          arr[1] = "dtan";

          arr[2] = "www.jb51.net";

          arr[3] = DateTime.Today.ToString();

          arr[4] = "歡迎來到腳本之家";

          CreateHtmlBLL.CreateHtmlBLL chb = new CreateHtmlBLL.CreateHtmlBLL();

          chb.CreateHtml("CreateHtml.config", "web/website","Template/TemplatePage.htm", arr,"Porschev");

        }

        catch (Exception ex)

        {

          throw ex;

        }

    }

    #endregion

    希望本文所述對大家asp.net程序設(shè)計有所幫助。

    更多信息請查看網(wǎng)絡(luò)編程

    2026上岸·考公考編培訓報班

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)