Here is a simple function to generate the RSS feeds.
This article assumes that you are using MVC4 project with Entity Framework. Just iterate through
the relevant table to pick your data which you want to show in the RSS feed.
Remember to add the following import statements at the top of your controller
Imports System.Xml
Imports System.IO
In your controller create a function as shown below. There is no need to create a corresponding View for it
as the function will write to the RESPONSE and the XML output will be provided by the XMLTextWriter.
Function RSSNewArticles() As Action
Response.Clear()
Response.ContentType = “text/xml”
Dim objX As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
objX.WriteStartDocument()
objX.WriteStartElement(“rss”)
objX.WriteAttributeString(“version”, “2.0”)
objX.WriteStartElement(“channel”)
objX.WriteElementString(“title”, “MyWebsite.com RSS Feed“)
objX.WriteElementString(“link”, “http://mywebsite.com“)
objX.WriteElementString(“description”, “My website New Articles Feed“)
‘ objX.WriteElementString(“copyright”, “(c) 2014, best-answer.net“)
objX.WriteElementString(“ttl”, “10”)‘Populate record for the RSS feed
For Each item In db.MyDataTable
objX.WriteStartElement(“item”)
objX.WriteElementString(“title”, item.CatName)
objX.WriteElementString(“link”, “http://mywebsite/” & item.RecordID & “/” & item.TitleName)
objX.WriteElementString(“pubDate”, Now)
objX.WriteEndElement()
NextobjX.WriteEndElement()
objX.WriteEndElement()
objX.WriteEndDocument()
objX.Flush()
objX.Close()
Response.End()
End Function