创建自己的RSS

為{幸葍}努か 提交于 2019-11-26 21:26:52

 

None.gif本文主要提供代码,创建自己的RSS,供别人订阅dot.gif
None.gif
None.gif
--- RSS.aspx
None.gif
None.gif
<%@ Page language="c#" Codebehind="RSS.aspx.cs" AutoEventWireup="false" Inherits="Socent.RSS" %>
None.gif
None.gif
--- RSS.aspx.cs
None.gif
None.gif
using System;
None.gif
using System.Collections;
None.gif
using System.ComponentModel;
None.gif
using System.Data;
None.gif
using System.Drawing;
None.gif
using System.Web;
None.gif
using System.Web.SessionState;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.HtmlControls;
None.gif
None.gif
namespace Socent
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif 
/**//// <summary>
InBlock.gif 
///  取得聚合文章
ExpandedSubBlockEnd.gif 
/// </summary>

InBlock.gif public class RSS : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  Components.GenRSS gr 
= new Components.GenRSS(); // 实例化对象
InBlock.gif

InBlock.gif  
string strRSS = "";
InBlock.gif
InBlock.gif  
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   Response.ContentType 
= "application/xml"// 输出并按xml数据显示
InBlock.gif
   Response.Write (GetRSS());
ExpandedSubBlockEnd.gif  }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 取得聚合文章
ExpandedSubBlockEnd.gif  
/// </summary>

InBlock.gif  public string GetRSS()
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{   
InBlock.gif   DataSet ds 
= gr.GenerateRSS(); // 调用GenerateRSS()方法,获得数据
InBlock.gif

InBlock.gif   strRSS 
= strRSS + "<rss version=\"2.0\">";
InBlock.gif   strRSS 
= strRSS + "<channel>";
InBlock.gif   strRSS 
= strRSS + "<title>土人制造</title>";
InBlock.gif   strRSS 
= strRSS + "<link>http://www.socent.com</link>";
InBlock.gif   strRSS 
= strRSS + "<description>土人制造</description>";
InBlock.gif   
for(int i = 0; i < ds.Tables[0].Rows.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    strRSS 
= strRSS + "<item>";
InBlock.gif    strRSS 
= strRSS + "<title><![CDATA["+ds.Tables[0].Rows[i]["Title"]+"]]></title>";
InBlock.gif    strRSS 
= strRSS + "<link>http://www.socent.com/ArticleShow@"+ds.Tables[0].Rows[i]["ID"]+".html</link> ";
InBlock.gif    strRSS 
= strRSS + "<description><![CDATA["+ds.Tables[0].Rows[i]["Description"]+"]]></description>";
InBlock.gif    strRSS 
= strRSS + "<copyright>土人制造</copyright>";
InBlock.gif    strRSS 
= strRSS + "<pubDate>"+Convert.ToDateTime(ds.Tables[0].Rows[i]["AddDate"].ToString()).ToString("yyyy-MM-dd HH:mm")+"</pubDate>";
InBlock.gif    strRSS 
= strRSS + "<comments>http://www.socent.com/CommentShow@"+ds.Tables[0].Rows[i]["ID"]+".html</comments>";
InBlock.gif    strRSS 
= strRSS + "</item>";
ExpandedSubBlockEnd.gif   }

InBlock.gif   strRSS 
= strRSS + "</channel>";
InBlock.gif   strRSS 
= strRSS + "</rss>";
InBlock.gif   
InBlock.gif   
return strRSS;
ExpandedSubBlockEnd.gif  }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif  
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
InBlock.gif  
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
//
InBlock.gif   
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
InBlock.gif   
//
InBlock.gif
   InitializeComponent();
InBlock.gif   
base.OnInit(e);
ExpandedSubBlockEnd.gif  }

InBlock.gif  
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif  
/// 此方法的内容。
ExpandedSubBlockEnd.gif  
/// </summary>

InBlock.gif  private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{    
InBlock.gif   
this.Load += new System.EventHandler(this.Page_Load);
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif  
#endregion

ExpandedSubBlockEnd.gif }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/T_98Dsky/archive/2005/05/24/161167.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!