C#
  Home arrow C# arrow Page 4 - Creating an RSS Feed with ASP.Net Written ...
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

Creating an RSS Feed with ASP.Net Written in C#
By: Luke Niland
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 20
    2007-07-02

    Table of Contents:
  • Creating an RSS Feed with ASP.Net Written in C#
  • Creating the Pages
  • Code Behind Page
  • The Data Repeater

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Creating an RSS Feed with ASP.Net Written in C# - The Data Repeater


    (Page 4 of 4 )

    Now we have all the logic in place. We can finish off the rss.aspx page we started earlier. The Repeater control is already bound to our results from the query, so we use it now to output the content to the XML page. First we create the control on the page.

    <asp:Repeater id="rptRSS" runat="server">

    Then we use the HeaderTemplate tags to define the start of the XML file.

      <HeaderTemplate>

        <rss version="2.0">

          <channel>

            <title>NW PA Feed (TEST)</title>

            <link>http://nw-editiis1/nwpafeed/</link>

            <description>This is a RSS Feed</description>

      </HeaderTemplate>

    This is the start of the XML file, and is giving it basic information about this feed. This is very simplistic, but it is telling the RSS reader application the version of RSS to which we are writing and the title of the feed, as well as giving it a link to the feed and the feed's description.

    This is a very simple example of a feed. More options are available such as links to a header image and so on. See http://www.rss-specifications.com/ for details.

    Now we will drop the individual items into the page.

    <ItemTemplate>

    <item>

    <title><%#FormatForXML(DataBinder.Eval(Container.DataItem,"slug"))%>

    </title>

    <description>

    <%#FormatForXML(DataBinder.Eval(Container.DataItem, "story"))%>

    </description>

    <link>http://server1/story?storyid=<%#DataBinder.Eval(Container.DataItem, "id")%>

    </link>

    <pubdate>

    <%#String.Format("{0:R}",DateTime.Now%>

    </pubdate>

    </item>

    </ItemTemplate>

    For each of the items for which we have queried the database, we call the FormatForXML function we wrote and pass it the current record and the file in which we are interested.

    To get the actual data out of the repeater, we call the dataBinder.Eval method, and pass it the data item. This item can be the name of the field or its integer value from 0 depending on the order they are returned from the query.

    Remember, we need to run the data through the format function to remove some of the XML reserved characters.

    When writing my version of this application, I had to make a few tweaks to the format function due to my data containing some other characters that XML didn't seem to like. These included some non-Windows line endings and some extended ASCII codes. I also made sure the headlines and main story text were only up to a certain length to improve readability and encourage the user to click on the link to the main story.

    We also put the current date and time in the PubDate field, but you might already have this information in your database for each story.

    Now that we've gotten the main data into the repeater, we need to write the footer tags in, and close the ASP repeater control, like this:

      <FooterTemplate>

          </channel>

        </rss>

      </FooterTemplate>

    </asp:Repeater>

    You now should be able to test your RSS feed. Fire up a modern browser (IE7 or Firefox; IE 6 will just display the XML) and navigate to the web URL on your web server where you dropped the code. You should be able to subscribe to the page and see all the news items.

    If you click on one of your items it will take you off to the URL you specified in the link section of your XML repeater code.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hi, Hope you like the article and find it useful, its a fairly straight forward...
       · Great explanations. Not like most on the net. Anyway, just a small correction in...
       · Hi,Glad you liked the explanations i try to keep them as simple as possible....
       · How Aboutdata = data.Replace("\"", """);
       · However...you lost me at step 2. Not your fault, but it all looks like Greek to...
     

    C# ARTICLES

    - Exceptions in C#
    - Overriding versus Overloading
    - Value Types and Reference Types
    - Defining Member and Type Visibility
    - Managing Files in C#
    - Working with Windows Registry in C#
    - Lossless Image Resizing in C#
    - Lossless Image Converting in C#
    - Creating an RSS Feed with ASP.Net Written in...
    - Polymorphism in C#
    - Inheritance in C#
    - C# Events Explained
    - C# Delegates Explained
    - C# StreamReader and StreamWriter Explained
    - C# FileStream Explained

    Iron Speed




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway