Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » XML » General » Downloads
 
Add your own
alternative version

What is RSS, and reading and writing RSS feeds

, 24 Feb 2010 CPOL
This article explains what RSS is and how we can read and write RSS feeds.
using System;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml;
using System.Text;

public partial class RSSWrite : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnPublish_Click(object sender, EventArgs e)
    {
        Response.Clear();
        XmlTextWriter RSSFeed = new XmlTextWriter(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "AvgPriceList.xml",Encoding.UTF8);
        // Write the rss tags like title, version, Channel, title, link description copyright etc. 
        RSSFeed.WriteStartDocument();
        RSSFeed.WriteStartElement("rss");
        RSSFeed.WriteAttributeString("version", "2.0");
        RSSFeed.WriteStartElement("channel");
        RSSFeed.WriteElementString("title", "Products Above Average Prices");
        RSSFeed.WriteElementString("link", "http://localhost/RSSFeeds");
        RSSFeed.WriteElementString("description", "Details of all the Products Average Prices");
        RSSFeed.WriteElementString("copyright", "Copyright Indrajeeth 2010");

        //here I am binding grid using SQLdatasource, This is for the example purpose reading from gridview 
        //it is not recomended use gridview, datatables,dataset to write data
        // Loop through the Gridview of the database and add them to the RSS feed

        foreach (GridViewRow grvRow in grvRSS.Rows)
        {
            RSSFeed.WriteStartElement("item");
            RSSFeed.WriteElementString("ProductName", grvRow.Cells[0].Text);
            RSSFeed.WriteElementString("UnitPrice", grvRow.Cells[1].Text);
            RSSFeed.WriteElementString("Link", "http://localhost/RSSFeeds/ProductList.xml");
            RSSFeed.WriteElementString("PublishDate", DateTime.Now.ToString());
            RSSFeed.WriteEndElement();
        }
        RSSFeed.WriteEndElement();
        RSSFeed.WriteEndElement();
        RSSFeed.WriteEndDocument();
        RSSFeed.Flush();
        RSSFeed.Close();
        Response.Write("RSS Feed is created. For reading Rss feed <a href='RSSRead.aspx'>Click here.</a>");
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Indrajeet Sutar
Software Developer (Junior) Excel Informatics, Pune
India India
Am Indrajeet T. Sutar. I am a web developer. I am working on .net technology. I have completed my Masters in Computers and Management (people call it as MCA, MBA etc.) Apart from programming i do photography (not regularly though), traveling and reading books.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150301.1 | Last Updated 24 Feb 2010
Article Copyright 2010 by Indrajeet Sutar
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid