当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 建立自己的RSS

ASP.NET
Asp.Net使用POST方法最简单的实现
实现.NET应用程序的自动更新
优秀ASP.NET程序员修炼之路
ASP.NET中实现模板页
在ASP.Net 2.0中实现多语言界面的方法
小议优化ASP.NET应用性能之Cache篇
.net开发投票机的思路
浅析CMS内容管理系统的两种方案
ASP.NET 2.0中动态修改页面标题
“您无权查看该网页”的原因和解决方法
将一个图片按比例缩放显示在一个Frame中
编程使用资源文件实现多语言页面(In Action)
.Net编程的多个小技巧
asp.net2.0学习历程-菜鸟到中级程序员的飞跃
asp.net如何连接sql server2000数据库
FCKeditor 2.6在ASP.NET中的配置方法
使用ASP.NET开发移动通讯的几种方法
ASP.NET 2.0的URL映射的实现方法
如何在Asp.net中使用HtmlArea编辑器
ASP.NET 2.0 中实现跨页提交

ASP.NET 中的 建立自己的RSS


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 53 ::
收藏到网摘: n/a

本文主要提供代码,创建自己的RSS,供别人订阅...

---RSS.aspx

<%@Pagelanguage="c#"Codebehind="RSS.aspx.cs"AutoEventWireup="false"Inherits="Socent.RSS"%>

---RSS.aspx.cs

usingSystem;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Web;
usingSystem.Web.SessionState;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.HtmlControls;

namespaceSocent
{
///<summary>
///取得聚合文章
///</summary>
publicclassRSS:System.Web.UI.Page
{
Components.GenRSSgr=newComponents.GenRSS();//实例化对象

stringstrRSS="";

privatevoidPage_Load(objectsender,System.EventArgse)
{
Response.ContentType="application/xml";//输出并按xml数据显示
Response.Write(GetRSS());
}

///<summary>
///取得聚合文章
///</summary>
publicstringGetRSS()
{
DataSetds=gr.GenerateRSS();//调用GenerateRSS()方法,获得数据

strRSS=strRSS+"<rssversion=\"2.0\">";
strRSS=strRSS+"<channel>";
strRSS=strRSS+"<title>土人制造</title>";
strRSS=strRSS+"<link>http://www.socent.com</link>";
strRSS=strRSS+"<description>土人制造</description>";
for(inti=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.socent.com/ArticleShow@"+ds.Tables[0].Rows[i]["ID"]+".html</link>";
strRSS=strRSS+"<description><![CDATA["+ds.Tables[0].Rows[i]["Description"]+"]]></description>";
strRSS=strRSS+"<copyright>土人制造</copyright>";
strRSS=strRSS+"<pubDate>"+Convert.ToDateTime(ds.Tables[0].Rows[i]["AddDate"].ToString()).ToString("yyyy-MM-ddHH:mm")+"</pubDate>";
strRSS=strRSS+"<comments>http://www.socent.com/CommentShow@"+ds.Tables[0].Rows[i]["ID"]+".html</comments>";
strRSS=strRSS+"</item>";
}
strRSS=strRSS+"</channel>";
strRSS=strRSS+"</rss>";

returnstrRSS;
}

#regionWeb窗体设计器生成的代码
overrideprotectedvoidOnInit(EventArgse)
{
//
//CODEGEN:该调用是ASP.NETWeb窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

///<summary>
///设计器支持所需的方法-不要使用代码编辑器修改
///此方法的内容。
///</summary>
privatevoidInitializeComponent()
{
this.Load+=newSystem.EventHandler(this.Page_Load);
}
#endregion
}
}