"Sonal" <sm*********@gm ail.com> wrote in message
news:b3******** *************** ***@posting.goo gle.com...
Hi
I am trying to provide infrastructure for RSS feeds on my Website. I
dont intend to build any news aggregators. I just want my website to
be enabled for providing RSS Feeds. I am using ASP.NET and C#. And I
dont know where and how to begin. Do you know of any tutorials that
may help me do that?
Thanks,
Sonal.
Here is a simple ASPX example, the NewsDAL implemenation is left as an
exercise for the reader :)
<!-- RSS.ASPX -->
<%@ Page language="vb" ContentType="te xt/xml" Codebehind="rss .aspx.vb"
AutoEventWireup ="false" Inherits="news. rss" EnableSessionSt ate="False"
enableViewState ="False" buffer="True"%>
<asp:Repeater id="rptRSS" runat="server">
<HeaderTemplate >
<rss version="2.0">
<channel>
<title><%=Chann elTitle%></title>
<link><%=Channe lLink%></link>
<description>
<%=ChannelDescr iption%>
</description>
</HeaderTemplate>
<ItemTemplate >
<item>
<title><%# FormatForXML(Da taBinder.Eval(C ontainer.DataIt em, "Title"))
%></title>
<description><% # FormatForXML(Da taBinder.Eval(C ontainer.DataIt em,
"Descriptio n")) %></description>
<link>http://<%=Request.Serv erVariables("SE RVER_NAME") &
Request.Applica tionPath %>/Story.aspx?ID=< %#
DataBinder.Eval (Container.Data Item, "ArticleID" ) %></link>
<author><%# FormatForXML(Da taBinder.Eval(C ontainer.DataIt em, "Author"))
%></author>
<pubDate><%# String.Format(" {0:R}", DataBinder.Eval (Container.Data Item,
"DatePublished" )) %></pubDate>
</item>
</ItemTemplate>
<FooterTemplate >
</channel>
</rss>
</FooterTemplate>
</asp:Repeater>
' rss.aspx.vb
Imports System.Xml
Public Class rss
Inherits System.Web.UI.P age
Public ChannelTitle As String = ""
Public ChannelLink As String = ""
Public ChannelDescript ion As String = ""
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub
#End Region
Protected WithEvents rptRSS As System.Web.UI.W ebControls.Repe ater
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim ArticleCount As Integer
Dim ChannelID As Integer
Dim data As NewsDAL.Data = New NewsDAL.Data(Gl obal.ConnString )
Try
Try
ArticleCount = Integer.Parse(R equest.QueryStr ing("Count"))
Catch
ArticleCount = 5
End Try
Try
ChannelID = Integer.Parse(R equest.QueryStr ing("ChannelID" ))
Catch
ChannelID = 1
End Try
Dim ds As New DataSet
data.FillRSSCha nnels_Get(ds, ChannelID)
Dim dr As DataRow = ds.Tables(0).Ro ws(0)
ChannelTitle = FormatForXML(dr ("Title").ToStr ing())
ChannelLink = FormatForXML(dr ("Link").ToStri ng())
ChannelDescript ion = FormatForXML(dr ("Description") .ToString())
Catch ex As Exception
Response.Clear( )
Response.Write([String].Format("<error >Channel {0}</error>", ex.Message))
Response.End()
End Try
Try
Dim ds As New DataSet
data.FillArticl es_GetListForCh annel(ds, ArticleCount, ChannelID)
Dim dv As New DataView
dv.Table = ds.Tables(0)
dv.Sort = "DatePublis hed DESC"
rptRSS.DataSour ce = dv
rptRSS.DataBind ()
Catch ex As Exception
Response.Clear( )
Response.Write([String].Format("<error >Articles {0}</error>",
ex.Message))
Response.End()
End Try
data = Nothing
End Sub
Protected Function FormatForXML(By Val input As Object) As String
Dim s As String = input.ToString( ) '; // cast the input to a string
'// replace those characters disallowed in XML documents
s = s.Replace("&", "&")
s = s.Replace("""", """)
s = s.Replace("'", "'")
s = s.Replace("<", "<")
s = s.Replace(">", ">")
Return s
End Function
End Class