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 閱讀(330) 評論(0)  編輯  收藏 所屬分類: dot net相關

          導航

          常用鏈接

          留言簿(44)

          新聞檔案

          2.動態語言

          3.工具箱

          9.文檔教程

          友情鏈接

          搜索

          最新評論

          主站蜘蛛池模板: 曲松县| 德令哈市| 怀化市| 金塔县| 昌平区| 邢台市| 韶山市| 昌乐县| 晴隆县| 朔州市| 宿州市| 东兰县| 甘德县| 灵宝市| 平果县| 普安县| 都匀市| 岚皋县| 安康市| 铜川市| 青川县| 会昌县| 安吉县| 喀喇| 叶城县| 双牌县| 岢岚县| 会理县| 阿坝| 沙坪坝区| 寿宁县| 丁青县| 莆田市| 保山市| 鄂尔多斯市| 东明县| 车险| 南京市| 菏泽市| 佛冈县| 普宁市|