How To Build a RSS 2.0 Feed with ASP.NET 2.0
As an Internet Retailer you want to be able to release information as soon as possible. RSS (Really Simple Syndication) is just another way to quickly and easily release new information. For instance, you may want RSS feeds for your website you use to alert subscribers of changes to your websites, new content, additional services or new products. You may already have email subscribers for announcements like this. Don’t use RSS to replace your email, use it to compliment. Many times email does not get delivered or gets delivered to a junk mail folder. RSS does not suffer from these deliverability issues. Additionally, since RSS is a “pull” technology as opposed to email which is a “push” technology, some people are more inclined because they know that unlike email you can’t sell them out and if you start spamming them, they can simply stop downloading your feed.
The following images denote how email is pushed from your server to email clients and how RSS is different because the clients request the feed information from your server.


Creating an RSS feed is easy as well. The following example is source code to create an RSS 2.0 feed in ASP.NET 2.0.
Start with some imports:
Imports System.Web
Imports System.Xml
Now the subroutine that exposes your feed to the web page:
Sub PopFeed()
Response.Clear()
Response.ContentType = "text/xml"
Dim myXML As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
myXML.WriteStartDocument()
myXML.WriteStartElement("rss")
myXML.WriteAttributeString("version", "2.0")
myXML.WriteStartElement("channel")
myXML.WriteElementString("title", "Your Cool RSS Feed Title")
myXML.WriteElementString("link", "http://MyCoolSiteLink.com/RSS.ASPX") 'RSS Feed Link
myXML.WriteElementString("description", "My Cool RSS FEED Description")
myXML.WriteElementString("copyright", "(c) " & Now.Year.ToString)
' ***** Start First Entry *****
myXML.WriteStartElement("item")
myXML.WriteElementString("title", "Internet Retailer Blog")
myXML.WriteElementString("description", "Check out the Intenet Retailer Blog to find tips and techniques to making your ecommerce business a success!")
myXML.WriteElementString("link", "Http://www.InternetRetailerBlog.com")
myXML.WriteElementString("pubdate", "9/1/2008")
myXML.WriteEndElement()
' ***** End First Entry *****
myXML.WriteEndElement()
myXML.WriteEndElement()
myXML.WriteEndDocument()
myXML.Flush()
myXML.Close()
Response.End()
End Sub
Note the start and end of the first entry. This is where you would loop through a dataset if you wanted to pull your feed data from a database. And just to be complete, don’t forget to call your PopFeed routine in the page_load event:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
PopFeed()
End Sub
It’s that easy…