asp.net基于替换模版页的形式生成静态页的方法__第1页
asp.net基于替换模版页的形式生成静态页的方法__第2页
asp.net基于替换模版页的形式生成静态页的方法__第3页
asp.net基于替换模版页的形式生成静态页的方法__第4页
asp.net基于替换模版页的形式生成静态页的方法__第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、基于替换模版页的形式生成静态页的方法_ 本文实例讲解并描述了基于替换模版页的形式生成静态页的方法。分享给大家供大家参考,具体如下: 第一步:新建项目,创建一个简洁模版页:TemplatePage.htm !DOCTYPE html PUBLIC -/W3C/DTD XHTML 1.0 Transitional/EN l1/DTD/xhtml1-transitional.dtd html xmlns=l head titlePorschev 生成静态页简洁示例/title /head body h1$Porschev0$/h1 ul li页标题:$Porschev0$/li li名称:$Pors

2、chev1$/li li网址:a href=$Porschev2$ target=_blank$Porschev2$/a/li li时间:$Porschev3$/li li详述:$Porschev4$/li /ul /body /html 其次步:创建一个config文件:CreateHtml.config ?xml version=1.0 encoding=utf-8 ? web website key=0 value=title/ website key=1 value=name/ website key=2 value=url/ website key=3 value=createDat

3、e/ website key=4 value=desc/ /web 第三步:编写生成静态页代码:(添加System.Web引用) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Xml; namespace CreateHtmlBLL public class CreateHtmlBLL #region#读取配置文件某节点的个数 /summary / 读取配置文件某节点的个数 /summary /param na

4、me=path配置文件的路径/param /param name=nodeName要猎取的节点/param /returns返回节点个数/returns private int ReadConfig(string path,string nodeName) string absoPath = string.Empty; /肯定路径 try absoPath = System.Web.HttpContext.Current.Server.MapPath(path); XmlDocument xd = new XmlDocument(); xd.Load(absoPath); XmlNodeLis

5、t nodeList = xd.SelectNodes(nodeName); /得到相应节点的集合 return nodeList.Count; catch (Exception) throw; #endregion #region#创建文件夹 /summary / 创建文件夹 /summary /param name=path要创建的路径/param public void CreatFolder(string path) string absoPath = string.Empty; /肯定路径 try absoPath = System.Web.HttpContext.Current.S

6、erver.MapPath(path); if (!Directory.Exists(absoPath) Directory.CreateDirectory(absoPath); catch (Exception) throw; #endregion #region#生成HTML页 /summary / 生成HTML页 /summary /param name=configPath配置文件的路径/param /param name=configNodeName配置文件节点名/param /param name=temPath模版页路径/param /param name=arr替换数组/par

7、am /param name=createPath生成HTML路径/param public void CreateHtml(string configPath, String configNodeName, string temPath, string arr,string createPath) string fileName = string.Empty; /生成文件名 string absoCrePath = string.Empty; /生成页肯定路径 string absoTemPath = string.Empty; /模版页的肯定中径 int nodeCount = 0; /节

8、点数 try absoCrePath = System.Web.HttpContext.Current.Server.MapPath(createPath); absoTemPath = System.Web.HttpContext.Current.Server.MapPath(temPath); nodeCount = ReadConfig(configPath, configNodeName); FileStream fs = File.Open(absoTemPath, FileMode.Open, FileAccess.Read); /读取模版页 StreamReader sr = n

9、ew StreamReader(fs, Encoding.GetEncoding(utf-8); StringBuilder sb = new StringBuilder(sr.ReadToEnd(); sr.Close(); sr.Dispose(); for (int i = 0; i nodeCount; i+) sb.Replace($Porschev + i + $, arri); CreatFolder(createPath); fileName = DateTime.Now.ToFileTime().ToString() + .html; /设置文件名(这里可以依据需要改变命名)

10、 FileStream cfs = File.Create(absoCrePath + / + fileName); StreamWriter sw = new StreamWriter(cfs, Encoding.GetEncoding(utf-8); sw.Write(sb.ToString(); sw.Flush(); sw.Close(); sw.Dispose(); catch (Exception) throw; #endregion 第四步:测式生成 protected void Page_Load(object sender, EventArgs e) CreateHtml(); #region#生成静态页 /summary / 生成静态页 /summary public void CreateHtml() try string arr = new string5; arr0 = Porschev 静态页测式; arr1 = dtan; arr2 = ; arr3 = DateTime.Today.ToString(); arr4 = 欢迎来到脚本之家; CreateHtmlBLL.CreateHtmlBLL chb = new CreateHtmlB

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论