ASP.NET生成HTML页
来源:互联网 发布:内脏脂肪怎么减 知乎 编辑:程序博客网 时间:2024/06/11 21:28
//生成HTML页
public static bool WriteFile(string strText,string strContent,string strAuthor)
{
string path = HttpContext.Current.Server.MapPath("/news/");
Encoding code = Encoding.GetEncoding("gb2312");
// 读取模板文件
string temp = HttpContext.Current.Server.MapPath("/news/text.html");
StreamReader sr=null;
StreamWriter sw=null;
string str="";
try
{
sr = new StreamReader(temp, code);
str = sr.ReadToEnd(); // 读取文件
}
catch(Exception exp)
{
HttpContext.Current.Response.Write(exp.Message);
HttpContext.Current.Response.End();
sr.Close();
}
string htmlfilename=DateTime.Now.ToString("yyyyMMddHHmmss")+".html";
// 替换内容
// 这时,模板文件已经读入到名称为str的变量中了
str =str.Replace("ShowArticle",strText); //模板页中的ShowArticle
str = str.Replace("biaoti",strText);
str = str.Replace("content",strContent);
str = str.Replace("author",strAuthor);
// 写文件
try
{
sw = new StreamWriter(path + htmlfilename , false, code);
sw.Write(str);
sw.Flush();
}
catch(Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
return true;
此函数放在Conn.CS基类中了
在添加新闻的代码中引用 注:工程名为Hover
if(Hover.Conn.WriteFilethis.Title.Text.ToString),this.Content.Text.ToString),this.Author.Text.ToString)))
{
Response.Write("添加成功");
}
else
{
Response.Write("生成HTML出错!");
}
模板页Text.html代码
CODE:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML >
<HEAD >
<title >ShowArticle </title >
<body >
biaoti
<br >
content <br >
author
</body >
</HTML >
public static bool WriteFile(string strText,string strContent,string strAuthor)
{
string path = HttpContext.Current.Server.MapPath("/news/");
Encoding code = Encoding.GetEncoding("gb2312");
// 读取模板文件
string temp = HttpContext.Current.Server.MapPath("/news/text.html");
StreamReader sr=null;
StreamWriter sw=null;
string str="";
try
{
sr = new StreamReader(temp, code);
str = sr.ReadToEnd(); // 读取文件
}
catch(Exception exp)
{
HttpContext.Current.Response.Write(exp.Message);
HttpContext.Current.Response.End();
sr.Close();
}
string htmlfilename=DateTime.Now.ToString("yyyyMMddHHmmss")+".html";
// 替换内容
// 这时,模板文件已经读入到名称为str的变量中了
str =str.Replace("ShowArticle",strText); //模板页中的ShowArticle
str = str.Replace("biaoti",strText);
str = str.Replace("content",strContent);
str = str.Replace("author",strAuthor);
// 写文件
try
{
sw = new StreamWriter(path + htmlfilename , false, code);
sw.Write(str);
sw.Flush();
}
catch(Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
return true;
此函数放在Conn.CS基类中了
在添加新闻的代码中引用 注:工程名为Hover
if(Hover.Conn.WriteFilethis.Title.Text.ToString),this.Content.Text.ToString),this.Author.Text.ToString)))
{
Response.Write("添加成功");
}
else
{
Response.Write("生成HTML出错!");
}
模板页Text.html代码
CODE:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML >
<HEAD >
<title >ShowArticle </title >
<body >
biaoti
<br >
content <br >
author
</body >
</HTML >
- ASP.NET生成HTML页
- ASP.NET生成HTML页
- ASP.Net/asp 生成静态HTML页
- asp.net生成HTML
- asp.net生成HTML
- asp.net生成html
- asp.net生成html
- asp.net 生成html
- [收藏]ASP.Net生成静态HTML页
- ASP.Net生成静态HTML页
- ASP.Net生成静态HTML页
- ASP.Net生成静态HTML页
- [收藏]ASP.Net生成静态HTML页
- ASP.Net生成静态HTML页
- ASP.Net生成静态HTML页
- asp.net生成html静态页页面。
- [收藏]ASP.Net生成静态HTML页
- ASP.Net生成静态HTML页,
- 解读无线网络的七大安全困惑
- 试验网站#1搜索引擎优化收录情况记录(断续运行)2007-10-30
- 试验网站#3搜索引擎优化收录情况记录2007-10-30
- 谷歌中国宣布启用简短域名g.cn
- 注册表的键删不了
- ASP.NET生成HTML页
- 防止黑客利用TTL值来鉴别操作系统
- 从CAO到CZO完全版
- 谷歌调整排序算法引发震荡 知名网站PR值下滑
- 蛮力法求最大子段
- 关于系统复杂性的一句箴言
- Smartupload和commons-fileupload介绍与比较(ZT)
- 内核中的调度与同步
- 将动态aspx页面转换成为静态html页面的几种方法