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

Posted by imomins on October 8, 2012 at 12:25 AM
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




Categories: ASP.NET, C#

Post a Comment

Oops!

Oops, you forgot something.

Oops!

The words you entered did not match the given text. Please try again.

You must be a member to comment on this page. Sign In or Register

1 Comment

Reply imomins
12:44 AM on October 10, 2012 
how to Create RSS feed Using Asp.net | RSS Feed Sample using asp.net