拾荒时代------技术,艺术!

.NET/Ajax/C#/Web2.0精品技术文章网摘。

导航

ASP.NET产生Rss文件

 1 --- RSS.aspx
 2 
 3 <%@ Page language="c#" Codebehind="RSS.aspx.cs" AutoEventWireup="false" Inherits="Socent.RSS" %>
 4 
 5 --- RSS.aspx.cs
 6 
 7 using System;
 8 using System.Collections;
 9 using System.ComponentModel;
10 using System.Data;
11 using System.Drawing;
12 using System.Web;
13 using System.Web.SessionState;
14 using System.Web.UI;
15 using System.Web.UI.WebControls;
16 using System.Web.UI.HtmlControls;
17 
18 namespace Socent
19 {
20  /// <summary>
21  ///  È¡µÃ¾ÛºÏÎÄÕÂ
22  /// </summary>
23  public class RSS : System.Web.UI.Page
24  {
25   Components.GenRSS gr = new Components.GenRSS(); // ÊµÀý»¯¶ÔÏó
26 
27   string strRSS = "";
28 
29   private void Page_Load(object sender, System.EventArgs e)
30   {
31    Response.ContentType = "application/xml"// Êä³ö²¢°´xmlÊý¾ÝÏÔʾ
32    Response.Write (GetRSS());
33   }
34 
35   /// <summary>
36   /// È¡µÃ¾ÛºÏÎÄÕÂ
37   /// </summary>
38   public string GetRSS()
39   {  
40    DataSet ds = gr.GenerateRSS(); // µ÷ÓÃGenerateRSS()•½•¨,»ñµÃÊý¾Ý
41 
42    strRSS = strRSS + "<rss version=\"2.0\">";
43    strRSS = strRSS + "<channel>";
44    strRSS = strRSS + "<title>ÍÁÈËÖÆÔì</title>";
45    strRSS = strRSS + "<link>http://www.socent.com</link>";
46    strRSS = strRSS + "<description>ÍÁÈËÖÆÔì</description>";
47    for(int i = 0; i < ds.Tables[0].Rows.Count; i++)
48    {
49     strRSS = strRSS + "<item>";
50     strRSS = strRSS + "<title><![CDATA["+ds.Tables[0].Rows[i]["Title"]+"]]></title>";
51     strRSS = strRSS + "<link>http://www.socent.com/ArticleShow@"+ds.Tables[0].Rows[i]["ID"]+".html</link> ";
52     strRSS = strRSS + "<description><![CDATA["+ds.Tables[0].Rows[i]["Description"]+"]]></description>";
53     strRSS = strRSS + "<copyright>ÍÁÈËÖÆÔì</copyright>";
54     strRSS = strRSS + "<pubDate>"+Convert.ToDateTime(ds.Tables[0].Rows[i]["AddDate"].ToString()).ToString("yyyy-MM-dd HH:mm")+"</pubDate>";
55     strRSS = strRSS + "<comments>http://www.socent.com/CommentShow@"+ds.Tables[0].Rows[i]["ID"]+".html</comments>";
56     strRSS = strRSS + "</item>";
57    }
58    strRSS = strRSS + "</channel>";
59    strRSS = strRSS + "</rss>";
60   
61    return strRSS;
62   }
63 
64   #region Web ´°ÌåÉè¼ÆÆ÷Éú³ÉµÄ´úÂë
65   override protected void OnInit(EventArgs e)
66   {
67    //
68    // CODEGEN: ¸Ãµ÷ÓÃÊÇ ASP.NET Web ´°ÌåÉè¼ÆÆ÷Ëù±ØÐèµÄ¡£
69    //
70    InitializeComponent();
71    base.OnInit(e);
72   }
73  
74   /// <summary>
75   /// Éè¼ÆÆ÷Ö§³ÖËùÐèµÄ•½•¨ - ²»ÒªÊ¹ÓôúÂë±à¼­Æ÷ÐÞ¸Ä
76   /// ´Ë•½•¨µÄÄÚÈÝ¡£
77   /// </summary>
78   private void InitializeComponent()
79   {   
80    this.Load += new System.EventHandler(this.Page_Load);
81   }
82   #endregion
83  }
84 }
85 

posted on 2007-06-10 13:20  拾荒时代  阅读(455)  评论(0编辑  收藏  举报