.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Lets Generate RSS Feeds : A practical scenario

Posted By:Gaurav Arora       Posted Date: April 28, 2009    Points: 25    Category: ASP.NET    URL: http://www.dotnetspark.com  
 

Around a week back one of my colleagues need to generate RSS Feed for Site in ASP.Net using C#. This is my try towards the same.

Here, I have used database of my site and try to generate a RSS Feed for my Site.
Anyone can use the same with a little change.
1. As this will generate a RSS Feed so there is no need to do more with design page only besides few following lines 


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="RSSFeedGenerator.aspx.cs" Inherits="RSSFeedGenerator" EnableViewState="false"%>
<%@ OutputCache Duration="300" VaryByParam="none"  %>





    Simple RSS Feed Generator


   
   


   
   

   



2. In the code-behind page every thing need to be written as :


/* This Example is a part of different
 * examples shown in Book:
 * C#2005 Beginners: A Step Ahead
 * Written by: Gaurav Arora
 * Reach at : Gaurav Arora*/
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Web;
using System.Xml;

public partial class RSSFeedGenerator : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();
        Response.ContentType = "text/xml";
        XmlTextWriter objX = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
        objX.WriteStartDocument();
        objX.WriteStartElement("rss");
        objX.WriteAttributeString("version","2.0");
        objX.WriteStartElement("channel");
        objX.WriteElementString("title", "A new Web Developer Installer Launched by MicroSoft");
        objX.WriteElementString("link", "http://www.msdotnetheaven.com");
        objX.WriteElementString("description", "I am very happy to read this news as a Web Developer that MicroSoft launched A free Web Platform installer and its free! It provides : 1. Install entire microSoft Web Platform 2.Quickly get started web application using MS Utilities like asp.net and MVC, silverlight etc. 3. Includes updated IIS with version 7.0 Its worth ...");
        objX.WriteElementString("copyright","(c) 2008, MsDotNetHeaven News. All rights reserved.");
        objX.WriteElementString("ttl","5");

        SqlConnection objCon = new SqlConnection(ConfigurationSettings.AppSettings["conString"]);
        objCon.Open();
       
        //Change your feed table and query
        string sql = "SELECT TOP 10 Title, Summary, ArticleID, PostTime FROM Articles ORDER BY PostTime DESC";
       
        SqlCommand objCmd = new SqlCommand(sql, objCon);
        SqlDataReader objReader = objCmd.ExecuteReader();
       
        while (objReader.Read())
        {
            objX.WriteStartElement("item");
            objX.WriteElementString("title",objReader.GetString(0));
            objX.WriteElementString("description",objReader.GetString(1));
            objX.WriteElementString("link", "http://www.msdotnetheaven.com/?p=" + objReader.GetInt32(2).ToString());
            objX.WriteElementString("pubDate", objReader.GetDateTime(3).ToString("R"));
            objX.WriteEndElement();
        }
        objReader.Close();
        objCon.Close();

        objX.WriteEndElement();
        objX.WriteEndElement();
        objX.WriteEndDocument();
        objX.Flush();
        objX.Close();
        Response.End();
    }
}


Following are the step(s):
1. Start Visual Studio
2. Create a new project
3. Add above two files
4. Press F5
There are some specification to follow when RSS Feed generates : RSS Feed Specification

The following is the feed document :


 


     MsDotNetHeaven
     http://www.msdotnetheaven.com
     Lets Share Knowledge...
     Sat, 18 Oct 2008 20:49:57 +0000
     http://backend.userland.com/rss092
     en
    
    
           A new Web Developer Installer Launched by MicroSoft
           I am very happy to read this news as a Web Developer that MicroSoft launched A free Web Platform installer and its free!

It provides :
1. Install entire microSoft Web Platform
2.Quickly get started web application using MS Utilities like asp.net and MVC, silverlight etc.
3. Includes updated IIS with version 7.0

Its worth ...

           http://www.msdotnetheaven.com/?p=106
                 

    
           Embedding "Windows Media Player" into a web page
           Hey Friends!!!

Would you like to know, how can we integrate Windows "Media Player" through ASP.NET?

Isn't it pretty interesting? If yes, then please go through my post below:

You probably saw many websites that include an embeded video player in their pages. Most of the time, the embedded video player is ...

           http://www.msdotnetheaven.com/?p=37
                 

    
           Adobe new release : Flash Player 10
           On Wednesday Adobe shipped its new Flash Player version 10 with main feratures:
1. 3D capabilities build in feature
2. Developers can add their own special effects
3. Upgraded to rich internet technology

With the above release it is cleared that now Adobe featuring to web applications with folowing some extra features:
1. Online video
2. ...

           http://www.msdotnetheaven.com/?p=34
                 

    
           Silverlight2.0 : releases on Monday
           Get ready for Silverlight2.0 release on MondayI got the news from one of my friend and want to share the same with you. MicroSoft decided to release Silverlight2.0 on Monday.I have not more for its:1. Features2. Working3. New implementations4. Flexibility etc.Only the idea is that its a great inventions in ...
           http://www.msdotnetheaven.com/?p=104
                 

    
           Monday : A day for Silverlight2.0 release
           Get ready for Silverlight2.0 release on Monday

I got the news from one of my friend and want to share the same with you. MicroSoft decided to release Silverlight2.0 on Monday.

I have not more for its:
1. Features
2. Working
3. New implementations
4. Flexibility etc.
Only the idea is that its a great inventions in ...

           http://www.msdotnetheaven.com/?p=30
                 





 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend