生成静态页面并分页源码

原创 2007年09月19日 10:11: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 Mysqlserver;
using System.IO;
using System.Text;
namespace NewsAdd
{
    public partial class Admin_AdminPanel_NewsAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string strDate = DateTime.Now.ToString("yyMMdd") + "/" + DateTime.Now.ToString("yyyymmddhhmmss");
            string strFileName = strDate + ".shtml";
            string strTitle=Request.Form["Title"].ToString().Trim();
            string strContent=Request.Form["Content"].ToString().Trim();
            string[] content = strContent.Split(new Char[] ...{'|'});
            int upbound = content.Length;
            SqlServerDataBase db = new SqlServerDataBase();
            bool success = db.Insert("insert into inNews(Title,Content,FilePath)values('" + strTitle + "','" + strContent + "','" + strFileName + "')", null);

            string dir = Server.MapPath("../../"+"NewsFiles/"+DateTime.Now.ToString("yyMMdd"));
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            try
            {
            for (int i = 0; i < content.Length; i++)
            {
            //string[] newContent = new string[4];
            StringBuilder strhtml = new StringBuilder();
                using (StreamReader sr = new StreamReader(Server.MapPath("../../" + "NewsFiles/") + "/template.html",Encoding.GetEncoding("gb2312")))
                {
                    String oneline;
                    while ((oneline = sr.ReadLine()) != null)
                    {
                        strhtml.Append(oneline);
                    }
                    sr.Close();
                }
            DataSet ds = db.Select("select top 1 NewsId from inNews order by NewsId desc", null);
            string strTable = "<table><tr><td>$upUrl</td><td>$Number</td><td>$downUrl</td></tr></table>";
                string FilePath="";
                strhtml = strhtml.Replace("$Title", strTitle);
                strhtml = strhtml.Replace("$NewsId", ds.Tables[0].Rows[0]["NewsId"].ToString());
                strhtml = strhtml.Replace("$Time", DateTime.Now.ToString("yyyy/MM/dd"));
                strhtml = strhtml.Replace("$Content", content[i]);
                string strNumber = "";
                for (int m = 1; m <=upbound; m++)
                {
                    if (m == 1)
                        strNumber = strNumber + " ["+"<a href=" + "../" + strDate + ".shtml" + ">" + m + "</a>"+"] ";
                    else
                    {
                        int n = m - 1;
                        strNumber = strNumber + " [" +"<a href=" + "../" + strDate + "_" + n + ".shtml" + ">" +  m + "</a>"+"] ";
                    }
                }
                    if (upbound == 0)
                    {
                        FilePath = Server.MapPath("../../") + "NewsFiles" + "//" + strDate + ".shtml";
                        strhtml = strhtml.Replace("$Pager", "");
                    }
                    else
                    {
                        if (i == 0)
                            FilePath = Server.MapPath("../../") + "NewsFiles" + "//" + strDate + ".shtml";
                        else
                            FilePath = Server.MapPath("../../") + "NewsFiles" + "//" + strDate + "_" + i + ".shtml";
                       
                        if (i == 0)
                            strTable = strTable.Replace("$upUrl", "");

                        if (i <= 1)//上一页分页
                            strTable = strTable.Replace("$upUrl", "<a href=" + "../" + strDate + ".shtml" + ">上一页</a>");
                        else
                        {
                            int p = i - 1;
                            strTable = strTable.Replace("$upUrl", "<a href=" + "../" + strDate + "_" + p + ".shtml" + ">上一页</a>");
                        }
                       
                        if(upbound==1)
                        strTable = strTable.Replace("$Number", "");
                        else
                        strTable = strTable.Replace("$Number", strNumber);
                        if(i==upbound-1)
                            strTable = strTable.Replace("$downUrl", "");

                        if (i != upbound - 1)
                        {
                            int q = i + 1;
                            strTable = strTable.Replace("$downUrl", "<a href=" + "../" + strDate + "_" + q + ".shtml" + ">下一页</a>");
                        }
                        else
                        {
                            int j = upbound - 1;
                            strTable = strTable.Replace("$downUrl", "<a href=" + "../" + strDate + "_" + j + ".shtml" + ">下一页</a>");
                        }

                        strhtml = strhtml.Replace("$Pager", strTable);
                    }
                FileInfo finfo = new FileInfo(FilePath);
                using (FileStream fs = finfo.OpenWrite())
                {
                    StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default);
                    sw.WriteLine(strhtml);
                    sw.Flush();
                    sw.Close();
                }
            }
        }
        catch (Exception err)
        {
            Response.Write(err.ToString());
        }
        }
}
}

 

 

生成静态页面并有分页效果

  • 2009年04月18日 08:23
  • 1.1MB
  • 下载

Asp.NET生成静态页面并分页

  • 2008年07月20日 21:53
  • 3KB
  • 下载

利用PHP与Smarty模板技术生成分页静态页面的代码

ear_all_cache();//清除所有缓存 //smarty.php //create html file use smarty template //Rossy.cn@gmial.c...

.NET生成静态页面并分页

主要的原理就是替换模板里的特殊字符。 1、静态模板页面 template.html,主要是定义了一些特殊字符,用来被替换。   $Title $T...

ASP.NET静态页面生成代码及分页

ASP.NET静态页面生成代码 1、静态模板页面 template.html,主要是定义了一些特殊字符,用来被替换。1.               2.               3.      ...

Asp.NET生成静态页面并分页

因为公司的产品用asp开发, 前一段时间用asp写了一个生成静态页面并分页的程序,但缘于对.net的热爱,写了这个.net下的生成静态页面并分页的程序。 主要的原理就是替换模板里的特殊字符。 ...

php生成静态页面源码

  • 2017年11月18日 20:04
  • 1KB
  • 下载

生成纯静态页面 源码演示

生成纯静态html页面 可自定义后缀显示 源码演示 http://www.jizhuni.com/forum.php?mod=viewthread&tid=361 (出处: .Net开发 C#学习...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:生成静态页面并分页源码
举报原因:
原因补充:

(最多只允许输入30个字)