asp.net生成静态页
类别: ASP.NET教程
//生成HTML页
public static bool WriteFile(string strText,string strContent,string strAuthor)
{
string path = HttpContext.Current.Server.MapPath(\"/news/\");
= Encoding.GetEncoding(\"gb2312\");
// 读取模板文件
string temp = HttpContext.Current.Server.MapPath(\"/news/text.html\");
=null;
=null;
string str=\"\";
try
{
= new StreamReader(temp, code);
= sr.ReadToEnd(); // 读取文件
}
catch(Exception exp)
{
string htmlfilename=DateTime.Now.ToString(\"yyyyMMddHHmmss\")+\".html\";
// 替换内容
// 这时,模板文件已经读入到名称为str的变量中了
str =str.Replace(\"ShowArticle\",strText); //模板页中的ShowArticle
str = str.Replace(\"biaoti\",strText);
= str.Replace(\"content\",strContent);
= str.Replace(\"author\",strAuthor);
// 写文件
try
{
= new StreamWriter(path + htmlfilename , false, code);
catch(Exception ex)
{
finally
{
return true;
if(Hover.Conn.WriteFilethis.Title.Text.ToString),this.Content.Text.ToString),this.Author.Text.ToString)))
{
\"添加成功\");
else
{
\"生成HTML出错!\");
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" >
<HTML>
<HEAD>
<title>ShowArticle</title>
<body>
<br>
<br>
</body>
</HTML>
<br>
<br>
</body>
</HTML>
public static bool WriteFile(string strText,string strContent,string strAuthor)
{
string path = HttpContext.Current.Server.MapPath(\"/news/\");
= Encoding.GetEncoding(\"gb2312\");
// 读取模板文件
string temp = HttpContext.Current.Server.MapPath(\"/news/text.html\");
=null;
=null;
string str=\"\";
try
{
= new StreamReader(temp, code);
= sr.ReadToEnd(); // 读取文件
}
catch(Exception exp)
{
string htmlfilename=DateTime.Now.ToString(\"yyyyMMddHHmmss\")+\".html\";
// 替换内容
// 这时,模板文件已经读入到名称为str的变量中了
str =str.Replace(\"ShowArticle\",strText); //模板页中的ShowArticle
str = str.Replace(\"biaoti\",strText);
= str.Replace(\"content\",strContent);
= str.Replace(\"author\",strAuthor);
// 写文件
try
{
= new StreamWriter(path + htmlfilename , false, code);
catch(Exception ex)
{
finally
{
return true;
if(Hover.Conn.WriteFilethis.Title.Text.ToString),this.Content.Text.ToString),this.Author.Text.ToString)))
{
\"添加成功\");
else
{
\"生成HTML出错!\");
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" >
<HTML>
<HEAD>
<title>ShowArticle</title>
<body>
<br>
<br>
</body>
</HTML>
<br>
<br>
</body>
</HTML>
- 上一篇: 顺序求出c(n,r)的排列组合
- 下一篇: 根据数据库生成xml二法
-= 资 源 教 程 =-
文 章 搜 索