会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
yongwnet
博客园
首页
新随笔
联系
订阅
管理
asp.net 生成html 简单示例
模板文件内容:
mb.html
<
html
>
<
head
>
<
title
>
Create Html
</
title
>
</
head
>
<
body
>
<
form
id
="form1"
>
<
div
>
<
table
>
<
tr
>
<
td
>
<
br
><
br
>
title:$title$
<
br
><
br
>
content:$content$
<
br
><
br
>
</
td
>
</
tr
>
</
table
>
</
div
>
</
form
>
</
body
>
</
html
>
代码:
using
System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Text;
using
System.IO;
public
partial
class
_Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
string
mbPath
=
"
c:\\mb.html
"
;
Encoding code
=
Encoding.GetEncoding(
"
gb2312
"
);
StreamReader sr
=
null
;
StreamWriter sw
=
null
;
string
str
=
null
;
//
读取
try
{
sr
=
new
StreamReader(mbPath, code);
str
=
sr.ReadToEnd();
}
catch
(Exception ex)
{
throw
ex;
}
finally
{
sr.Close();
}
string
fileName
=
DateTime.Now.ToString(
"
yyyyMMddHHmmss
"
)
+
"
.shtml
"
;
str
=
str.Replace(
"
$title$
"
,
"
mytitle
"
);
str
=
str.Replace(
"
$content$
"
,
"
myContent
"
);
//
写入
try
{
sw
=
new
StreamWriter(
"
c:\\
"
+
fileName,
false
, code);
sw.Write(str);
sw.Flush();
}
catch
(Exception ex)
{
throw
ex;
}
finally
{
sw.Close();
}
}
}
生成后的文件内容:
20070515010734.shtml
<
html
>
<
head
>
<
title
>
Create Html
</
title
>
</
head
>
<
body
>
<
form id
=
"
form1
"
>
<
div
>
<
table
>
<
tr
>
<
td
>
<
br
><
br
>
title:mytitle
<
br
><
br
>
content:myContent
<
br
><
br
>
</
td
>
</
tr
>
</
table
>
</
div
>
</
form
>
</
body
>
</
html
>
posted @
2007-05-15 01:12
yongwnet
阅读(
322
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告