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.文檔教程

          友情鏈接

          搜索

          最新評論

          主站蜘蛛池模板: 青冈县| 喀什市| 沧源| 长泰县| 玉林市| 神池县| 墨江| 子长县| 宣威市| 鹤峰县| 寿宁县| 桐乡市| 红河县| 漠河县| 乌恰县| 额尔古纳市| 泉州市| 沁源县| 霞浦县| 昭苏县| 桃园市| 公安县| 襄垣县| 武陟县| 白银市| 霍州市| 安仁县| 蓝田县| 金山区| 新蔡县| 长顺县| 民勤县| 贵南县| 清河县| 建瓯市| 浮梁县| 汪清县| 介休市| 宾川县| 高密市| 牙克石市|