asp.net 生成静态html页面
2012-06-21 09:23
716 查看
方案:
1,利用模板生成html
2,将文件title和文件名称保存到数据库
生成.aspx
模板 Template.htm
1,利用模板生成html
2,将文件title和文件名称保存到数据库
生成.aspx
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Text; using System.IO; using System.Web.UI.HtmlControls; public partial class CMS : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Unnamed1_Click(object sender, EventArgs e) { WriteFile("hello world", ""); } public void WriteFile(string strText,string strAuthor) { String path = Server.MapPath("news/"); Encoding code = Encoding.GetEncoding("gb2312"); //读取模板 String temp = Server.MapPath("Template.htm"); 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 filename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html"; //替换内容 str = str.Replace("$replacecontent", strText); try { sw = new StreamWriter(path + filename, false, code); sw.Write(str); sw.Flush(); Response.Write("<a href='./news/" + filename + "'>strText</a>"); } catch (Exception exp) { HttpContext.Current.Response.Write(exp.Message); HttpContext.Current.Response.End(); sr.Close(); } finally { sw.Close(); } } }
模板 Template.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>新闻中心</title> </head> <body> $replacecontent </body> </html>
相关文章推荐
- ASP.NET生成静态HTML页面的方法
- ASP.NET生成静态HTML页面
- C#(asp.net)根据静态模板生成静态(html)页面
- ASP.NET 生成HTML静态页面实例
- ASP.Net生成静态HTML页面{转2}
- 使用ASP.NET模板生成HTML静态页面的五种方案
- ASP.NET生成静态HTML页面并分别按年月目录存放
- ASP.NET生成静态HTML页面并分别按年月目录存放
- asp.net(c#)生成静态html页面
- asp.net(c#)生成静态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页面{转2}