日期:2014-05-18  浏览次数:20917 次

c#生成html文件问题 急 急 急 急 急 急 急 急 急 急 急 急 急 急 急 急 急 急 急 急
//cs
 string[] format=new string[4];//定义和htmlyem标记数目一致的数组  
   
    StringBuilder htmltext=new StringBuilder();  
   
    try  
   
    {  
   
     using (StreamReader sr = new StreamReader("E:/muyegg/head.html"))  
   
     {  
   
    String line;  
   
    while ((line = sr.ReadLine()) != null)  
   
    {  
   
     htmltext.Append(line);  
   
    }  
   
    sr.Close();  
   
     }  
   
    }  
   
    catch  
   
    {  
   
     Response.Write("<Script>alert('读取文件错误')</Script>");  
   
    }  
   
    //---------------------给标记数组赋值------------  
   
    format[0]="background='bg.jpg'";//背景图片  
   
    format[1]="#990099";//字体颜色  
   
    format[2]="150px";//字体大小  
   
    format[3]="<marquee>生成的模板html页面</marquee>";//文字说明  
   
    //----------替换htm里的标记为你想加的内容  
   
    for(int i=0;i<4;i++)  
   
    {  
   
     htmltext.Replace("$cebu["+i+"]",format[i]);  
   
    }  
   
    //----------生成htm文件------------------――  
   
    try  
   
    {  
   
     using(StreamWriter sw=new StreamWriter("E:/muyegg/inc/",false,System.Text.Encoding.GetEncoding("GB2312")))  
   
    {  
   
     sw.WriteLine(htmltext);  
   
     sw.Flush();  
   
     sw.Close();
  Response.Write("<script>window.alert('首页文件html生成成功');</script>");
    }  
   
    }  
   
    catch  
    {  
   
    Response.Write("The file could not be wirte:");  
   
    }
//模版 
<html>
<head>
<title></title>
<meta http-equiv="Content-type" content="text/html; charset=gb2312" />
</head>
<body>
<table style="height:100%; border:0px; width:100%; height:$cebu[0]; background-color:#eeeeee; border:1px solid #000000" cellpadding="10px" cellspacing="0px">
<tr>
<td style="width:100%; vertical-align:middle;" align="left">
<span style="color:$cebu[1]; font-size:$cebu[2]">$cebu[3]</span>
</td>
</tr>
</table>
</body>
</html>
1.能找到模版页
高手请帮我看看 我第一次搞实在不懂 代码网上找的

------解决方案--------------------
就是用了模板页替换,有什么问题?