Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Generating an RSS feed using .NET

I've been trying to follow a tutorial to dynamically generate an RSS feed - I'm not getting any errors, but when I call the page, I just get a blank screen.

Here's my feed.aspx code:

<%@ Page Language="VB" AutoEventWireup="false" src="RSS.aspx.vb" Inherits="LMC.RSS.RSS" EnableViewState="false" %>
<%@ OutputCache Duration="300" VaryByParam="none" %>

And here's my vb code:

Imports System
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports System.Web
Imports System.Xml

Namespace LMC.RSS
Public Class RSS
Inherits System.Web.UI.Page

Private Sub Page_Load(sender As Object, e As System.EventArgs)
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", "Le Moyne College Newsflash")
objX.WriteElementString("link", "http://www.lemoyne.edu/news/feed.aspx")
objX.WriteElementString("description", "Today's News and Events from Around the Le Moyne College Campus")
objX.WriteElementString("copyright", "(c) 2006 Le Moyne College. All rights reserved.")
objX.WriteElementString("ttl", "20")
Dim objConnection As New SqlConnection("Provider=SQLOLEDB;Data Source=xxxxx;Initial Catalog=xxxxx;User Id=xxxxx;Password=xxxxx;")
objConnection.Open()
Dim sql As String = "SELECT NewsHeadline, NewsDetails, NewsNo, NewsExpDate FROM DailyNews ORDER BY NewsExpDate DESC"
Dim objCommand As New SqlCommand(sql, objConnection)
Dim objReader As SqlDataReader = objCommand.ExecuteReader()
While objReader.Read()
objX.WriteStartElement("item")
objX.WriteElementString("title", objReader.GetString(0))
objX.WriteElementString("description", objReader.GetString(1))
objX.WriteElementString("link", "http://www.lemoyne.edu/rss/GetArticle.aspx?id=" + objReader.GetInt32(2).ToString())
objX.WriteElementString("pubDate", objReader.GetDateTime(3).ToString("R"))
objX.WriteEndElement()
End While
objReader.Close()
objConnection.Close()
objX.WriteEndElement()
objX.WriteEndElement()
objX.WriteEndDocument()
objX.Flush()
objX.Close()
Response.End()

End Sub
End Class

End Namespace

Since I'm not getting an error, I'm stumped as to how to proceed to figure out what's wrong!

Any help would be most appreciated!
[3064 byte] By [mtarby] at [2007-11-11 9:58:46]
# 1 Re: Generating an RSS feed using .NET
Have you tried View Source in the browser? Maybe you're getting the data back but the browser can't display it because it's not HTML?
Phil Weber at 2007-11-11 23:12:11 >
# 2 Re: Generating an RSS feed using .NET
Sorry - I was so focused on the code, I didn't think of that - the source is completely blank.
mtarby at 2007-11-11 23:13:11 >
# 3 Re: Generating an RSS feed using .NET
Hmm. You may find this article helpful: http://www.philweber.com/articles/easy_rss_in_vbnet.htm
Phil Weber at 2007-11-11 23:14:15 >
# 4 Re: Generating an RSS feed using .NET
Thanks - I'll check it out!
mtarby at 2007-11-11 23:15:20 >