Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

how to Create RSS feed Using Asp.net | RSS Feed Sample using asp.net

Apr 3, 2010
Introduction:

Here I will explain how to create RSS feed using asp.net.

Description:

RSS stands for "Really Simple Syndication". RSS solves a problem for people who regularly use the web. It allows you to easily stay informed by retrieving the latest content from the sites you are interested in. You save time by not needing to visit each site individually.

To implement RSS feed concept using asp.net just follow below steps
Step 1: Create Table In tblRss SQl Server as below. 

ColumnName
DataType
ID
int
Title
varchar(50)
Description
varchar(50)
Url
Varchar(50)
Step 2: Insert the Data In to the tblRss some Dummy data Url must be related Rss Link just like this

ID
Title
Description
Url
1
Test
testing
http://aspdotnet-suresh.com
2
aspdotnet
aspdotnet-suresh
http://aspdotnet-suresh.com
Step 3: In Default.aspx page add these 2 lines of code.     

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ OutputCache Duration="120" VaryByParam="*" %>

Step4: In code behind


using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

public partial class GridviewEditUpdate : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string connectionString = "Data Source=MYCBJ017550027;Initial Catalog=MySamplesDB;Integrated Security=True";
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(connectionString);
using (conn)
{
SqlDataAdapter ad = new SqlDataAdapter("SELECT * from tblRSS", conn);
ad.Fill(dt);
}

Response.Clear();
Response.ContentType = "text/xml";
XmlTextWriter TextWriter = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
TextWriter.WriteStartDocument();
//Below tags are mandatory rss
TextWriter.WriteStartElement("rss");
TextWriter.WriteAttributeString("version", "2.0");
// Channel tag will contain RSS feed details
TextWriter.WriteStartElement("channel");
TextWriter.WriteElementString("title", "C#.NET,ASP.NET Samples and Tutorials");
TextWriter.WriteElementString("link", "http://aspdotnet-suresh.blogspot.com");
TextWriter.WriteElementString("description", "Free ASP.NET articles,C#.NET,ASP.NET tutorials and Examples,Ajax,SQL Server,Javascript,XML,GridView Articles and code examples -- by Suresh Dasari");
TextWriter.WriteElementString("copyright", "Copyright 2009 - 2010 aspdontnet-suresh.blogspot.com. All rights reserved.");
foreach (DataRow oFeedItem in dt.Rows)
{
TextWriter.WriteStartElement("item");
TextWriter.WriteElementString("title", oFeedItem["Title"].ToString());
TextWriter.WriteElementString("description", oFeedItem["Description"].ToString());
TextWriter.WriteElementString("link", oFeedItem["URL"].ToString());
TextWriter.WriteEndElement();
}
TextWriter.WriteEndElement();
TextWriter.WriteEndElement();
TextWriter.WriteEndDocument();
TextWriter.Flush();
TextWriter.Close();
Response.End();
}
}
     
Demo




If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

26 comments :

Dwayne said...

small error in your code
1) //Below tags are mandatory rss tagTextWriter.WriteStartElement("rss"); should be two lines

//Below tags are mandatory rss tag
TextWriter.WriteStartElement("rss");

2)this gave an error so I deleted it
using System.Linq;

Otherwise it works great! :)

Suresh Dasari said...

Thanks Dwayne thanks for rectify my mistake i modified the code now it's working fine

chinuexpert said...

hey hi,
i create an application by following above procedure & steps but on front page i.e. on aspx page which control we should use to display rss feeds? plz tell me it's important for me.

Suresh Dasari said...

@chinuexpert,
No need of any control just create the page based on above process and run it output will display.

Anonymous said...

grt work

Anonymous said...

nice post

Shafeeq said...

awsome you are

Anonymous said...

Tell me something about Sharepoint also..

Anonymous said...

i got a result in xml format

Anonymous said...

thanx a lot sir

Anonymous said...

This feed contains errors. Internet Explorer will try updating this feed again later.iam getting this as result.Ihave 12 rows of data but display onli one row .

Unknown said...

my result in xml format. how can i get rss feeds

Anonymous said...

in chrome....the result is xml format.how to get actual rss feeds

Anonymous said...

grt post
thanks

Janaki Lenagala said...

Hi, I want to create a RSS feed for a asp.net web page by using jquery.How should I do? please help me..

Leslie C said...

3 years later and this code and still good. I needed a simple rss solution and this got me up and running in no time. Thank you for the post!

Unknown said...

This XML file does not appear to have any style information associated with it. The document tree is shown below.
i am applying this then my output like this error

Unknown said...

Your output is generating in rss.aspx page, but i've to do generate it in xml like rss.xml. How can i achieve this?

Unknown said...

i want display image in rss feed.......

Abhejeet Singh said...

hw i can genrate xml nd show it on browser???????????

Unknown said...

I want to display it on morquee html tag,please guide me how to do it.

khmer-kb said...

I got an error like this : "Line 11: public partial class GridviewEditUpdate : System.Web.UI.Page"

neetesh sharma said...

thanks

Anonymous said...

in chrome....the result is xml format.how to get actual rss feeds
Plz reply

Unknown said...

Dear sir
Can we read the rss or another site and store in our database

Lakhan said...

Thanks Sir, for this good article. Is there any library for creating RSS feed.

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.