ASP.NET生成Rss文件
RSS.aspx
<%@ Page language="c#" Codebehind="RSS.aspx.cs" AutoEventWireup="false" Inherits="51aspx.RSS" %>
RSS.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace 51aspx
{
/// <summary>
/// 生成Rss
/// </summary>
public class RSS : System.Web.UI.Page
{
Components.GenRSS gr = new Components.GenRSS();
string strRSS = "";
private void Page_Load(object sender, System.EventArgs e)
{
Response.ContentType = "application/xml";
Response.Write (GetRSS());
}
/// <summary>
/// GetRSS
/// </summary>
public string GetRSS()
{
DataSet ds = gr.GenerateRSS(); //
strRSS = strRSS + "<rss version=\"2.0\">";
strRSS = strRSS + "<channel>";
strRSS = strRSS + "<title>Asp.net</title>";
strRSS = strRSS + "<link>http://www.kyovcs.cn</link>";
strRSS = strRSS + "<description>聆聽風的輕響的博客</description>";
for(int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
strRSS = strRSS + "<item>";
strRSS = strRSS + "<title><![CDATA["+ds.Tables[0].Rows[i]["Title"]+"]]></title>";
strRSS = strRSS + "<link>http://www.kyovcs.cn/ArticleShow@"+ds.Tables[0].Rows[i]["ID"]+".html</link> ";
strRSS = strRSS + "<description><![CDATA["+ds.Tables[0].Rows[i]["Description"]+"]]></description>";
strRSS = strRSS + "<copyright>51aspx.com</copyright>";
strRSS = strRSS + "<pubDate>"+Convert.ToDateTime(ds.Tables[0].Rows[i]["AddDate"].ToString()).ToString("yyyy-MM-dd HH:mm")+"</pubDate>";
strRSS = strRSS + "<comments>http://www.kyovcs.cn/CommentShow@"+ds.Tables[0].Rows[i]["ID"]+".html</comments>";
strRSS = strRSS + "</item>";
}
strRSS = strRSS + "</channel>";
strRSS = strRSS + "</rss>";
return strRSS;
}
#region Web
override protected void OnInit(EventArgs e)
{
//
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}