zoukankan      html  css  js  c++  java
  • Rss订阅内容

    前台页面只有:

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %> 

     后台代码:

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Data.SqlClient;
    using System.Text;


        
    public partial class _Default : System.Web.UI.Page
        {

            
    protected void Page_Load(object sender, EventArgs e)
            {
                Response.ContentType 
    = "text/xml";
                Response.Write(GetRSS());
            }
            
    /// <summary>
            
    /// 取得聚合文章
            
    /// </summary>
            
    /// <returns></returns>
            public string GetRSS()
            {
                News t 
    = new News();//自己的业务类
                DataSet ds = t.GetListByClass(1);//根据类别得到数据

                StringBuilder strCode 
    = new StringBuilder();
                strCode.Append(
    "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>");
                strCode.Append(
    "<rss version='2.0' xmlns:dc=\"http://purl.org/dc/elements/1.1/\"");
                strCode.Append(" xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\" ");
                strCode.Append(" xmlns:wfw=\"http://wellformedweb.org/CommentAPI/\" xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\">");
                strCode.Append("<channel>");
                strCode.Append(
    "<title>Demo</title>");
                strCode.Append(
    "<link>http://" + Request.ServerVariables["SERVER_NAME"+ "</link> ");
                strCode.Append(
    "<description>11</description> ");
                strCode.Append(
    "<copyright>Copyright 2010</copyright> ");

                
    foreach (DataRow row in ds.Tables[0].Rows)
                {
                    
    string NewsId = row["NewsId"].ToString();
                    
    string Heading = row["Heading"].ToString();
                    
    string Content = row["Content"].ToString();
                    
    string IssueDate = row["IssueDate"].ToString();
                    
    string ClassId = row["ClassId"].ToString();


                    strCode.Append(
    "<item>");
                    strCode.Append(
    "<title>" + Heading + "</title>");
                    strCode.Append(
    "<link>http://" + Request.ServerVariables["SERVER_NAME"+ "/NewsShow.aspx?ID=" + NewsId + "</link>");
                    strCode.Append(
    "<subject>" + Content + "</subject>");
                    strCode.Append(
    "<description><![CDATA[" + Content + "]]></description>");
                    strCode.Append(
    "<PubDate>" + IssueDate + "</PubDate>");
                    strCode.Append(
    "<category>" + ClassId + "</category>");
                    strCode.Append(
    "</item>");
                }
                strCode.Append(
    "</channel>");
                strCode.Append(
    "</rss>");
                
    return strCode.ToString();
            }

            
    /// <summary>
            
    /// 获取数据类
            
    /// </summary>
            public class News
            {
                
    /// <summary>
                
    /// 获得数据列表
                
    /// </summary>
                public DataSet GetListByClass(int id)
                {
                    
    string strSQL = "select * from T_News order by NewsId";
                    
    return Query(strSQL);
                }

                
    /// <summary>
                
    /// 执行查询语句,返回DataSet
                
    /// </summary>
                
    /// <param name="SQLString">查询语句</param>
                
    /// <returns>DataSet</returns>
                public static DataSet Query(string SQLString)
                {
                    
    string conString = "data source=127.0.0.1;Database=test;user id=sa;password=";
                    
    using (SqlConnection connection = new SqlConnection(conString))
                    {
                        DataSet ds 
    = new DataSet();
                        
    try
                        {
                            connection.Open();
                            SqlDataAdapter command 
    = new SqlDataAdapter(SQLString, connection);
                            command.Fill(ds, 
    "ds");
                        }
                        
    catch (System.Data.SqlClient.SqlException ex)
                        {
                            
    throw new Exception(ex.Message);
                        }
                        
    return ds;
                    }
                }
            }

        }

       


  • 相关阅读:
    go---weichart个人对Golang中并发理解
    go语言值得学习的开源项目推荐
    mysql17---增量备份
    mysql16---读写分离
    mysql15--垂直分表水平分表
    mysql14---手动备份
    mysql13---索引使用注意
    mysql12----explain
    mysql11---主键普通全文索引
    OpenOffice的简单安装
  • 原文地址:https://www.cnblogs.com/chenqingwei/p/1756212.html
Copyright © 2011-2022 走看看