Create your own RSS

  • 2020-05-05 11:10:07
  • OfStack

This article provides code to create your own RSS for others to subscribe to...

--- RSS.aspx

< %@ Page language="c#" Codebehind="RSS.aspx.cs" AutoEventWireup="false" Inherits="Socent.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 Socent
{
  /// < summary >
  ///   get converged article
  /// < /summary >
  public class RSS : System.Web.UI.Page
  {
  Components. GenRSS gr = new Components. GenRSS(); // instantiate object

  string strRSS = "";

  private void Page_Load(object sender, System.EventArgs e)
  {
ContentType = "application/xml"; // output and display
according to xml data     Response.Write (GetRSS());
  }

  /// < summary >
  /// get the aggregated article
  /// < /summary >
  public string GetRSS()
  {    
    DataSet ds = gr.GenerateRSS(); // call the GenerateRSS() method to get the data

    strRSS = strRSS + " < rss version=\"2.0\" > ";
    strRSS = strRSS + " < channel > ";
    strRSS = strRSS + " < title > The natives made < /title > ";
    strRSS = strRSS + " < link > http://www.socent.com < /link > ";
    strRSS = strRSS + " < description > The natives made < /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.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 > The natives made < /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.socent.com/CommentShow@"+ds.Tables[0].Rows[i]["ID"]+".html < /comments > ";
      strRSS = strRSS + " < /item > ";
    }
    strRSS = strRSS + " < /channel > ";
    strRSS = strRSS + " < /rss > ";

    return strRSS;
  }

  #region Web form designer generates code
  override protected void OnInit(EventArgs e)
  {
    //
    // CODEGEN: this call is required for ASP.NET Web forms designer.
    //
    InitializeComponent();
    base.OnInit(e);
  }

  /// < summary >
  /// designer supports the required methods - do not use the code editor to modify
  /// the contents of this method.
  /// < /summary >
  private void InitializeComponent()
  {      
    this.Load += new System.EventHandler(this.Page_Load);
  }
  #endregion
  }
}


Related articles: