Tutorials and code for ASP.NET 2.0,C#,SQL Server,AJAX tutorials,jQuery  
Home    Articles    Contact Us
 

ASP.NET
AJAX
Interview Questions
Sql Server
Technology News
Tips and Tricks
jQuery

 

Generate RSS Feed in ASP.Net


RSS(Really Simple Syndication) is a Web content syndication format.RSS is used to publish frequently updated works—such as blog,news.Rss is simple XML file.

This article explain how to create RSS Feed using asp.net.

Simple Rss Format,
<rss version="2.0">
 <channel>
  <title>Test.com</title>
  <link>http://www.Test.com</link>
  <description>Test Articles</description>
 <item>
  <title>Generate-RSS-Feed-in-ASP.Net</title>
  <link>http://www.Test.com/Generate-RSS-Feed-in-ASP.Net.aspx</link>
  <description>Article Description.</description>
  </item>
</channel>
  </rss>

For More <a href=http://cyber.law.harvard.edu/rss/rss.html>Rss Attribute Info</a>

Code For Create Rss Feed in ASP.NET:

Class Used: 

  • Imports System.Xml
  • Imports System.Data.Common

Used XmlTextWriter for create RSS Feed.

 Dim cnn As SqlConnection
 Dim cmd As SqlCommand
 Dim dr As SqlDataReader
 Dim sql As String
 Dim objX As XmlTextWriter


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        cnn = New SqlConnection(ConfigurationManager.ConnectionStrings("con").ConnectionString)

        Response.Clear()
        Response.ContentType = "text/xml"
        objX = New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
        objX.WriteStartDocument()
        objX.WriteStartElement("rss")
        objX.WriteAttributeString("version", "2.0")

        objX.WriteStartElement("channel")
        objX.WriteElementString("title", "Test.com")
        objX.WriteElementString("link", http://www.Test.com)
        objX.WriteElementString("description", "Test Articles")

        sql = "SELECT Title,Description FROM tblArticle"
        cmd = New SqlCommand(sql, cnn)
        cnn.Open()
        dr = cmd.ExecuteReader()
        While dr.Read()
            objX.WriteStartElement("item")
            objX.WriteElementString("title", dr("Title"))
            objX.WriteElementString("link", String.Format("http://www.Test.com/{0}.aspx", dr("Title"))
            objX.WriteElementString("description", dr("Description"))
            objX.WriteEndElement()
    
        End While
        dr.Close()
        cnn.Close()
       
        objX.WriteEndElement()
        objX.WriteEndElement()
        objX.WriteEndDocument()
        objX.Flush()
        objX.Close()
        Response.End()
    End Sub

End Class

This code create RSS feed for your website.



User Comments:




Post Your Comment :


Name
Email:
Comment:

Home | Contact Us

© 2008-09 TechnoReader.com. All rights reserved.