How to Create RSS Feed in ASP.net

Generate RSS Feed using ASP.net



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", "new Scraps")
objX.WriteElementString("link", http://nscraps.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://nscraps.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


<<How to Create RSS Feed in PHP How to validate RSS feed >>


Related Topic What are All the Main Components Used in Android Application
How to Generate RSS Feed for Website
How to create RSS Feed
How to add Image in RSS Channel
How to add News in RSS feed
XML  RSS  RSS Feed  ASP  

nScraps.com 2011   Privacy Policy  Terms of Service  Feedback