2
Posted on 8:23 AM by prajeesh and filed under , , ,

RSS feeds or "Rich Site Summery" are XML documents that used to publish freequently updated works, and RSS document or Web feed includes full summerized text and meta data RSS is also known as "Really Simple Syndication". For detailed information regarding RSS Feeds visit here http://en.wikipedia.org/wiki/RSS_(file_format.
Sample RSS File


<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="0.91">
<channel>
<title>Prajeesh's ASP.net Tech blog</title>
<link>http://www.prajeeshkk.blogspot.com</link>
<description>Web development help - By Prajeeesh </description>
<language>en-us</language>
<image>
<title>Prajeesh's Blog</title>
<url>http://www.prajeeshkk.blogspot.com/</url>
<link>http://www.prajeeshkk.blogspot.com/</link>
<width>90</width>
<height>36</height>
</image>
<item>
<title>Attack Update</title>
<link>http://www.prajeeshkk.blogspot.com/</link>
<description>
This is a test content for my test RSS document:My blog contains posts based on Web development, Web design , ASP.net development, javascript, HTML and CSS
By Prajeesh, October 22, 2008
</description>
</item>
<item>
<title>Test Post Second.ca</title>
<link>http://www.prajeeshkk.blogspot.com/</link>
<description>
This is another post content for testing RSS feeds
By Prajeesh, October 22, 2008
</description>
</item>
</channel>
</rss>

Creatting an RSS Feed using asp.net with C#
Step 1
Create a class clsRss and copy following code in the class.
using System;using System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using System.Data.SqlClient;
using System.Text;
/// <summary>/// Summary description for clsRss

///
</summary>public class clsRss

{

clsArticle ObjArticle = new clsArticle();
public clsRss()
{

//
// TODO: Add constructor logic here//
}
public void CreateRss_Recent()
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "text/xml";XmlTextWriter objX = new XmlTextWriter(HttpContext.Current.Response.OutputStream, Encoding.UTF8);objX.WriteStartDocument();
objX.WriteStartElement("rss");
objX.WriteAttributeString("version","2.0");
objX.WriteStartElement("channel");
objX.WriteElementString("title", "prajeesh's Tech blog- Recent articles ");
objX.WriteElementString("link",http://www.testsite.com/rss.aspx);
objX.WriteElementString("description","Latest articles from your site .");objX.WriteElementString("copyright","(c) 2008, Your web solutions. All rights reserved.");
objX.WriteElementString("ttl","5");//
// Suppose Article_Recent_Rss() is a function that returns data table with columns Title,Description,link & Pubdate
//
DataTableReader objReader = ObjArticle.Artilce_Recent_Rss().CreateDataReader();
while (objReader.Read()){
objX.WriteStartElement("item");
objX.WriteElementString("title",objReader["Title"].ToString());
objX.WriteElementString("description",objReader["Summery"].ToString());
objX.WriteElementString("link",objReader["articleurl"].ToString() );
objX.WriteElementString("pubDate",objReader["Postdate"].ToString() );
objX.WriteEndElement();
}objReader.Close();
objX.WriteEndElement();
objX.WriteEndElement();
objX.WriteEndDocument();
objX.Flush();
objX.Close();
HttpContext.Current.Response.End();
}
}Step 2
in the page load event of feeds page, write the following code.
public partial class rss : System.Web.UI.Page
{
clsRss ObjRss = new clsRss();
protected void Page_Load(object sender, EventArgs e){
ObjRss.CreateRss_Recent(); }} Shout it kick it on DotNetKicks.com
2
Responses to ... Creating RSS Feeds using ASP.net
Saiful Alam said... October 13, 2008 at 11:19 AM

Nice post...

Jef Claes said... January 4, 2010 at 11:05 AM

Hey I came across this post on DotNetShoutOut. I don't want to hijack this post, but I blogged on this as well a while ago.

I used an RSS API that's built in the .NET framework.

You might find it interesting. (http://jclaes.blogspot.com/2009/10/rss-in-net.html).

Plus you've got yourself a new subscriber :)