使用C#生成RSS

1 <% @ Page language = " c# " Codebehind = " RSS.aspx.cs " AutoEventWireup = " false " Inherits = " Socent.RSS " %>
2
3 --- RSS.aspx.cs
4
5 using System;
6 using System.Collections;
7 using System.ComponentModel;
8 using System.Data;
9 using System.Drawing;
10 using System.Web;
11 using System.Web.SessionState;
12 using System.Web.UI;
13 using System.Web.UI.WebControls;
14 using System.Web.UI.HtmlControls;
15
16 namespace Socent
17 {
18  /// <summary>
19  /// 取得聚合文章
20  /// </summary>

21  public class RSS : System.Web.UI.Page
22  {
23  Components.GenRSS gr = new Components.GenRSS(); // 实例化对象
24
25  string strRSS = "";
26
27  private void Page_Load(object sender, System.EventArgs e)
28  {
29  Response.ContentType = "application/xml"; // 输出并按xml数据显示
30  Response.Write (GetRSS());
31  }

32
33  /// <summary>
34  /// 取得聚合文章
35  /// </summary>

36  public string GetRSS()
37  {
38  DataSet ds = gr.GenerateRSS(); // 调用GenerateRSS()方法,获得数据
39
40  strRSS = strRSS + "<rss version=/"2.0/">";
41  strRSS = strRSS + "<channel>";
42  strRSS = strRSS + "<title>土人制造</title>";
43  strRSS = strRSS + "<link>http://www.socent.com</link>";
44  strRSS = strRSS + "<description>土人制造</description>";
45  for(int i = 0; i < ds.Tables[0].Rows.Count; i++)
46  {
47  strRSS = strRSS + "<item>";
48  strRSS = strRSS + "<title><![CDATA["+ds.Tables[0].Rows[i]["Title"]+"]]></title>";
49  strRSS = strRSS + "<link>http://www.socent.com/ArticleShow@"+ds.Tables[0].Rows[i]["ID"]+".html</link> ";
50  strRSS = strRSS + "<description><![CDATA["+ds.Tables[0].Rows[i]["Description"]+"]]></description>";
51  strRSS = strRSS + "<copyright>土人制造</copyright>";
52  strRSS = strRSS + "<pubDate>"+Convert.ToDateTime(ds.Tables[0].Rows[i]["AddDate"].ToString()).ToString("yyyy-MM-dd HH:mm")+"</pubDate>";
53  strRSS = strRSS + "<comments>http://www.socent.com/CommentShow@"+ds.Tables[0].Rows[i]["ID"]+".html</comments>";
54  strRSS = strRSS + "</item>";
55  }

56  strRSS = strRSS + "</channel>";
57  strRSS = strRSS + "</rss>";
58  
59   return strRSS;
60  }

61
62  #region Web 窗体设计器生成的代码
63  override protected void OnInit(EventArgs e)
64  {
65   //
66   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
67   //
68   InitializeComponent();
69   base.OnInit(e);
70  }

71  
72  /// <summary>
73   /// 设计器支持所需的方法 - 不要使用代码编辑器修改
74   /// 此方法的内容。
75  /// </summary>

76   private void InitializeComponent()
77  {
78   this.Load += new System.EventHandler(this.Page_Load);
79  }

80   #endregion

81  }

82}

83
84
85
86
87
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值