您的位置:学习中国 故障解决 正文
原作者:admin 添加时间:2007-07-20 原文发表:2007-07-20 人气:126 来源:http://www.liuhui.org

本文章共3876字,分3页,当前第3页,快速翻页:
 

<span style="color: $htmlformat[1];font-size: $htmlformat[2]">$htmlformat[3]</span>

</td>

</tr>

</table>

</body>

</html>


2.asp.net代码:

//---------------------读html模板页面到stringbuilder对象里----

string[] format=new string[4];//定义和htmlyem标记数目一致的数组

StringBuilder htmltext=new StringBuilder();

try

{

using (StreamReader sr = new StreamReader("存放模板页面的路径和页面名"))

{ 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("$htmlformat["+i+"]",format[i]);

}

//----------生成htm文件------------------――

try

{

using(StreamWriter sw=new StreamWriter("存放路径和页面名",false,System.Text.Encoding.GetEncoding("GB2312")))

{

sw.WriteLine(htmltext);

sw.Flush();

sw.Close();

}

}

catch

{

Response.Write ("The file could not be wirte:");

}

小结
用此方法可以方便的生成html文件。程序使用了是循环替换,因此对需替换大量元素的模板速度非常快。


 
本文章更多内容<<上一页 - 1 - 2 - 3
本页地址
相关文章

静态页面生成技术及网上视频点播的实现方法
网站导航与网站地图有什么区别和联系?
网站策划随想
域名相关知识介绍
企业建站相关知识介绍
什么是域名解析,解析生效时间需要多长?
先消除十大网络的安全隐患 防范须知
常见Internet术语表
Internet国家或地区域名定义
先进加密标准
实现一个空间安装多个网站的两种方法
如何设计一个成功的网站?
商业网站建设设计原则
网站制作和网站推广有机结合
做一个中国式站长必须知道的五十个问题
什么是一级域名,二级域名
王通:网站推广的18种秘笈
垃圾站的流量为何那么高?
SEO新大陆,网页文件后缀大有文章
网站被百度K后,如何快速突破解禁,解封

相关评论


本文章所属分类:首页 故障解决   故障解决