Music. Coding. Gaming. Life.

FeedPage

Posted Tuesday, September 1st, 2009 6:48:00 pm
Because the code is so short, I've decided to just go ahead and post the code to FeedPage here. Remember, you must have a reference to the ASP.Net RSS Toolkit in order to compile this.

Imports RssToolkit.Rss
Imports System.Web.UI

Namespace roncliProductions.LibFeedPage

Public MustInherit Class FeedPage
    Inherits Page

    Protected Overrides Sub OnPreInit(ByVal e As System.EventArgs)
        MyBase.OnPreInit(e)
        Dim strFeed As String = Request.QueryString("feed")
        If Not String.IsNullOrEmpty(strFeed) Then
            If strFeed = "atom" Or strFeed = "opml" Or strFeed = "rdf" Or strFeed = "rss" Then
                Response.ContentType = "text/xml"
                Select Case strFeed
                    Case "atom"
                        Response.Write(GetFeed().ToXml(DocumentType.Atom))
                    Case "opml"
                        Response.Write(GetFeed().ToXml(DocumentType.Opml))
                    Case "rdf"
                        Response.Write(GetFeed().ToXml(DocumentType.Rdf))
                    Case "rss"
                        Response.Write(GetFeed().ToXml(DocumentType.Rss))
                End Select
            End If
            Response.End()
        End If
    End Sub

    Protected MustOverride Function GetFeed() As RssDocument

End Class

End Namespace


Easy enough. To use, simply change your inheritance from System.Web.UI.Page to roncliProductions.LibFeedPage.FeedPage, and inside that construct and return an RssDocument object. Then, when you add ?feed=xml to the URL of the page, you will get an RSS feed.

Comments

Loading...
roncli.com Media Player