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
ColumnName | DataType |
ID | int |
Title | varchar(50) |
Description | varchar(50) |
Url | Varchar(50) |
ID | Title | Description | Url |
1 | Test | testing | http://aspdotnet-suresh.com |
2 | aspdotnet | aspdotnet-suresh | http://aspdotnet-suresh.com |
<%@ 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(); } } |
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. |
|||
|
|||
25 comments :
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! :)
Thanks Dwayne thanks for rectify my mistake i modified the code now it's working fine
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.
@chinuexpert,
No need of any control just create the page based on above process and run it output will display.
grt work
nice post
awsome you are
Tell me something about Sharepoint also..
i got a result in xml format
thanx a lot sir
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 .
in chrome....the result is xml format.how to get actual rss feeds
grt post
thanks
Hi, I want to create a RSS feed for a asp.net web page by using jquery.How should I do? please help me..
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!
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
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?
i want display image in rss feed.......
hw i can genrate xml nd show it on browser???????????
I want to display it on morquee html tag,please guide me how to do it.
I got an error like this : "Line 11: public partial class GridviewEditUpdate : System.Web.UI.Page"
thanks
in chrome....the result is xml format.how to get actual rss feeds
Plz reply
Dear sir
Can we read the rss or another site and store in our database
Thanks Sir, for this good article. Is there any library for creating RSS feed.
Note: Only a member of this blog may post a comment.