blogjava's web log

          blogjava's web log
          ...

          asp.net生成靜態頁面[導入]

          思路:建個模版文件,再用C#讀此文件,把里面的標記替換掉。。

          < meta? http-equiv ="Content-Type" ?content ="text/html;?charset=gb2312" > ?
          </ head > ?
          < body? > ?
          < table? $htmlformat[0]?height ="100%" ?border ="0" ?width ="100%" ?cellpadding ="10" ?cellspacing ="0" ?bgcolor ="#eeeeee" ?style ="border:1px?solid?#000000" > ?
          < tr > ?
          < td? width ="100%" ?valign ="middle" ?align ="left" > ?
          < span? style ="color:?$htmlformat[1];font-size:?$htmlformat[2]" > $htmlformat[3] </ span > ?
          </ td > ?
          </ tr > ?
          </ table > ?
          </ body > ?
          </ html > ??

          ?

          ???? string []?format = new ? string [ 4 ]; // 定義和htmlyem標記數目一致的數組?
          ????????????StringBuilder?htmltext = new ?StringBuilder();?
          ????????????
          try ?
          ????????????
          {
           ????????????????
          using ?(StreamReader?sr? = ? new ?StreamReader(Server.MapPath( " aaa.htm " )))?
           ????????????????
          {?
          ????????????????????
          string ?line;
            ????????????????
          while ?((line? = ?sr.ReadLine())? != ? null )?
           ????????????????????
          {?
             ????????????????????htmltext.Append(line);?
            ????????????????}
          ?
            ????????????????sr.Close();?
           ????????????????}
          ?
          ????????????}
          ?
          ????????????
          catch (Exception?ex)
          ????????????
          {?
          ????????????????
          this .Response.Write(ex.Message);
          ????????????}
          ?
          ????????????format[
          0 ] = " background=\ " image.jpg\ "" ;
          ????????????format[
          1 ] = ? " red " ; // 字體顏色?
          ????????????format[ 2 ] = " 150px " ; // 字體大小?
          ????????????format[ 3 ] = ? " <marquee>生成的模板html頁面</marquee> " ; // 文字說明?
          ????????????
          // ----------替換htm里的標記為你想加的內容?
          ????????????htmltext.Replace( " [$title$] " , " abcd<hr>abckd<hr> " );
          // ????????????for(int?i=0;i<4;i++)?
          // ????????????{?
          //  ????????????????htmltexst.Replace("$htmlformat["+i+"]",format[i]);?
          // ????????????}?
          ????????????
          // ----------生成htm文件------------------――?
          ???????????? try ?
          ????????????
          {?
           ????????????
          using (StreamWriter?sw = new ?StreamWriter( @" c:\aa.html " , false ,System.Text.Encoding.GetEncoding( " GB2312 " )))?
          ????????????????????
          {?
           ????????????????????????sw.WriteLine(htmltext);?
           ????????????????????????sw.Flush();?
           ????????????????????????sw.Close();?
          ????????????????????}

          ????????????}

          ????????????
          catch (Exception?ex)
          ????????????
          {?
          ????????????????
          this .Response.Write(ex.Message);
          ????????????}
          ?

          ????????}

          posted on 2006-05-27 17:32 record java and net 閱讀(327) 評論(0)  編輯  收藏 所屬分類: dot net相關

          導航

          常用鏈接

          留言簿(44)

          新聞檔案

          2.動態語言

          3.工具箱

          9.文檔教程

          友情鏈接

          搜索

          最新評論

          主站蜘蛛池模板: 柳州市| 宜宾县| 宽城| 富宁县| 四会市| 肇庆市| 武隆县| 六盘水市| 白城市| 海淀区| 云阳县| 双流县| 通榆县| 读书| 炉霍县| 当阳市| 特克斯县| 嘉义县| 措勤县| 德清县| 九龙城区| 庐江县| 资源县| 报价| 威海市| 光山县| 稻城县| 轮台县| 基隆市| 交口县| 邢台县| 玉山县| 封开县| 福清市| 遂平县| 北宁市| 七台河市| 寿阳县| 巴彦县| 综艺| 冕宁县|