zoukankan
html css js c++ java
asp.net 生成静态页
先建个html模版页(template.htm):
<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"
>
<
html
>
<
head
>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=gb2312"
>
<
title
>
$title
</
title
>
</
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
>
在asp.net中的应用(c#):
string
[] format
=
new
string
[
4
];
//
定义和htmlyem标记数目一致的数组
StringBuilder htmltext
=
new
StringBuilder();
try
{
using
(StreamReader sr
=
new
StreamReader(
base
.Server.MapPath(
"
.
"
)
+
"
\\template.htm
"
))
{
String line;
while
((line
=
sr.ReadLine())
!=
null
)
{
htmltext.Append(line);
}
sr.Close();
}
}
catch
{
Response.Write(
"
<Script>alert('读取文件错误')</Script>
"
);
}
//
---------------------给标记数组赋值------------
string
title
=
"
模板测试
"
;
format[
0
]
=
"
background=\
"
bg.jpg\
""
;
//
背景图片
format[
1
]
=
"
#990099
"
;
//
字体颜色
format[
2
]
=
"
150px
"
;
//
字体大小
format[
3
]
=
"
<marquee>生成的模板html页面</marquee>
"
;
//
文字说明
//
----------替换htm里的标记为你想加的内容
htmltext.Replace(
"
$title
"
,title);
//
把title不放在数组是为了比较一下,:)。这样写比较容易看懂
for
(
int
i
=
0
;i
<
4
;i
++
)
//
这样写方便。如果写入模版的数据较多,我想为了清晰用上面的方法或许更好点。
{
htmltext.Replace(
"
$htmlformat[
"
+
i
+
"
]
"
,format[i]);
}
//
----------生成htm文件------------------――
try
{
using
(StreamWriter sw
=
new
StreamWriter(
base
.Server.MapPath(
"
.
"
)
+
"
\\test.htm
"
,
false
,System.Text.Encoding.GetEncoding(
"
GB2312
"
)))
{
sw.WriteLine(htmltext);
sw.Flush();
sw.Close();
}
}
catch
{
Response.Write (
"
您的权限不够,请与管理员联系!
"
);
}
from:
http://blog.csdn.net/JOHNCOOLS/archive/2006/09/20/1253105.aspx
查看全文
相关阅读:
难得之货,令人行妨
Oracle死锁
log4j杂记
Oracle9或11使用了Oracle10的驱动引起的时间丢失
程序员要重视过劳
oracle提供的有用函数(待续)
Mysql扩展之replication概述
@autowired与@qualifer的使用区别备忘
Oracle中的in参数的个数限制
java版正则式提取替换示例
原文地址:https://www.cnblogs.com/yiki/p/830704.html
最新文章
分布式文件系统FastDFS原理介绍 天高地厚
怎么查看用户的SQL执行历史 天高地厚
自旋锁 天高地厚
windows powershell
远程调用存储过程
SQLite3简介及在.Net程序中的使用
sql 根据字段查表名
动态TSQL语句常見問題與解決方案
获取数据库中的数据库有多少个
MSSQL日期推算本周一的日期和本周结束日期本月开始日期和本月结束日期
热门文章
(转)我心中的十大信息化软件开发技术
无法显示XML页名称以无效字符开头处理资源'http://xx'时出错的解决方法
Win7中IIS7安装配置
如何获得一个字符串中数字的长度
网页刷新方法集合
Jmeter分布式控制
Python编程从入门到实践 Eric Matthes 著 袁国忠 译 第二章 动手试一试
Python基础题 1
win7桌面IE图标恢复与取消
走出困境 日本电子企业的创新征程(1)(转载)
Copyright © 2011-2022 走看看