NET分页代码,生成静态页面 By admin 2009/11/10 23:13:00 using System; using System.Data; using System.Configuration; using System.Collections; 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.IO; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { WriteFile(" 要好好学啊!! ", "祝你找到一份好工作!!!", "别忘了我", "Jiawenquan.html"); } public void WriteFile(string strText, string content, string page, string name) { string path = HttpContext.Current.Server.MapPath("news/get"); System.Text.Encoding code = System.Text.Encoding.GetEncoding("gb2312"); // 读取模板文件 string temp = HttpContext.Current.Server.MapPath("news/text.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 htmlfilename = name.ToString(); // 替换内容 // 这时,模板文件已经读入到名称为str的变量中了 str = str.Replace("$title", strText); //模板页中的$title,即标题 str = str.Replace("$content", content);//模板页中的$content,即内容 str = str.Replace("$page", page);//模板页中的$page,即页码连接格式 // 写文件 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(); } } } 分享联系我们 扫二维码与项目经理沟通 我们在微信上24小时期待你的声音 感谢您的关注分享“NET分页代码,生成静态页面” 烟寒网络真诚为您服务 ,点击客服直接咨询下单. 立即咨询 我们服务 网站建设 高端网站建设服务商、相信品牌力量、相信知名企业;制作后收费13014982176! 微信小程序/微信公众号 微信小程序 背靠10亿流量,不论用户需求是什么,都能被开发使用 一点创意,就能在“社交圈”中脱颖而出。 网站优化/SEO 让您的网站更靠近排名位置,让客户更容易找到您,seo优化是一个漫长过程,整个网站营销花最少的钱起最大的作用。