• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

asp.net批量生成静态网页(二)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

<!—CreateHTML.aspx.cs -->

using System;

using System.Data;

using System.Data.SqlClient;

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;

using System.Text;

 

public partial class CreateHTML : System.Web.UI.Page

{

    public string title = "", content = "", datetime = "", desc = "", pages = "", nowPosition = "", positionlist = null, forindex = "";

 

    protected void Page_Load(object sender, EventArgs e)

    {

       

    }

 

    //获取文章内容

    private void GetArticle(string articles_id)

    {

        SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=city;database=test;");

        string sql = "select * from articles where articles_id=" + articles_id;

        SqlCommand cmd = new SqlCommand(sql, conn);

        conn.Open();

        SqlDataReader sdr = cmd.ExecuteReader();

        if (sdr.Read())

        {

            nowPosition = this.GetPosition(sdr["articlesgroup_parent_id"].ToString(), positionlist);

            title = sdr["title"].ToString();

            content = Server.HtmlDecode(sdr["article"].ToString());

            desc = sdr["articledescription"].ToString();

            datetime = sdr["articledatetime"].ToString();

            forindex += "<a href='article" + articles_id + ".html'>" + sdr["title"] + "</a><br />";

        }

        else

        {

            title = "";

            content = "";

            desc = "";

            datetime = "";

        }

        conn.Close();

    }

 

    //创建文章HTML

    private void Createhtml(string article_id)

    {

        this.GetArticle(article_id);

        if (title != "" && content != "")

        {//防止生成空数据的页面

            string[] format = new string[5];//定义和htmlyem标记数目一致的数组

            StringBuilder htmltext = new StringBuilder();

            try

            {

                using (StreamReader sr = new StreamReader(Server.MapPath("temp.htm")))

                {

                    String line;

                    while ((line = sr.ReadLine()) != null)

                    {

                        htmltext.Append(line);

                    }

                    sr.Close();

                }

            }

            catch

            {

                Response.Write("<Script>alert('读取文件错误')</Script>");

            }


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
如何在ASP.NETCore中使用Redis发布时间:2022-07-10
下一篇:
ASP.NETMVC的本地化支持(三)发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap