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

ASP.NET
ASP.NET上传图片时 产生预览
动态改变asp.net网页的标题
一个ASP.NET中使用的MessageBox类
ASP.NET设计网络硬盘之两重要类
ASP.NET与MySQL数据库简明图示入门教程
ASP.NET中为DataGrid添加合计字段
利用ASP.NET的内置功能抵御Web攻击
ASP.NET+Web服务实现软件共享
ASP.NET设计网络硬盘之文件夹实现
在ASP.NET中使用SQL的IN操作
datagrid与DataSet结合使用中出现的索引问题
asp.net开发web项目-vss集成环境配置
ASPX保存远程图片到本地的两种方法的函数
ASP.NET设计网络硬盘之删除文件夹
开发ASP.NET下的MP3小偷程序
对“学号”、“身份证”的数字分析
Asp.net url分页的用户控件
ASP.NET 2.0中DataTable小兵变大将
将dataset以xml形式发给客户端下载
ASP.NET实现自适应图片大小的弹窗 窗口可任意编辑

ASP.NET 中的 建立自己的RSS


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 46 ::
收藏到网摘: 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
}
}