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 阅读(318) 评论(0)  编辑  收藏 所属分类: dot net相关


只有注册用户登录后才能发表评论。


网站导航:
 

导航

常用链接

留言簿(44)

新闻档案

2.动态语言

3.工具箱

9.文档教程

友情链接

搜索

最新评论