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

          友情鏈接

          搜索

          最新評論

          主站蜘蛛池模板: 綦江县| 普格县| 舒兰市| 兴宁市| 庄河市| 苏州市| 刚察县| 师宗县| 鹿邑县| 娱乐| 平邑县| 淳化县| 湖州市| 岳阳县| 灵宝市| 宣汉县| 泸水县| 北海市| 紫阳县| 云安县| 南通市| 涞源县| 赤城县| 万盛区| 白城市| 金沙县| 剑河县| 炎陵县| 镇平县| 乌拉特中旗| 遵义市| 新绛县| 安龙县| 乡宁县| 凤庆县| 类乌齐县| 苏尼特右旗| 滕州市| 工布江达县| 孟连| 乌拉特后旗|