首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c#生成html文件有关问题 急 急 急 急 急 急 急 急 急 急 急 急 急 急 急 急 急 急 急

2012-01-19 
c#生成html文件问题 急 急 急 急 急 急 急 急 急 急 急 急 急 急 急 急 急 急 急 急//cs string[]formatn

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.能找到模版页
高手请帮我看看 我第一次搞实在不懂 代码网上找的

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


什么问题? 没写权限么?
[解决办法]

"E:/muyegg/inc/"
????这是什么?你不给文件名他知道是什么文件?
另外,建议catch后面最好带上(Exception e)。以免出错。
[解决办法]
还不就是你自己遍一个
[解决办法]
用XML+XSLT来生成html多好啊!!
[解决办法]
jf。。。

热点排行