Creating an RSS 2.0 feed with ASP.NET 2.0

by Graffen 10. January 2007 17:36

It's really easy - just use a repeater control:

<%@ Page Language="C#" ContentType="text/xml" MaintainScrollPositionOnPostback="false"
    AutoEventWireup="true" CodeBehind="NyheterRSS.aspx.cs" Inherits="NyheterRSS" %>

<%@ Import Namespace="mrfs" %>
<head id="Head1" runat="server" visible="false" />
<asp:sqldatasource runat="server" id="NewsDataSource" connectionstring="<%$ConnectionStrings:LocalSqlServer %>"
    selectcommand="SELECT id, title, abstract, text, publishdate, eventdate, aspnet_Users.UserName, archive                   
    FROM News                   
    LEFT JOIN aspnet_Users                   
    ON aspnet_Users.UserId = News.addedby                   
    WHERE archive='false' ORDER BY publishdate" />
<asp:repeater id="RssRepeater" runat="server" datasourceid="NewsDataSource">   
    <HeaderTemplate>      
        <rss version="2.0">         
        <channel>            
        <title><![CDATA[mrfs.se: Nyheter]]></title>            
        <link></link>            
        <description>Malmö Radioflygsällskaps Nyheter</description>            
        <copyright>Copyright 2006 Malmö Radioflygsällskap</copyright>    
    </HeaderTemplate>     
    <ItemTemplate>            
        <item>               
            <title><![CDATA[<%# Eval("title") %>]]></title>               
            <author><![CDATA[<%# Eval("addedby") %>]]></author>               
            <description><![CDATA[<%# Eval("text") %>]]></description>               
            <link></link>               
            <pubDate><%# string.Format("{0:R}", Eval("publishdate")) %></pubDate>            
        </item>   
    </ItemTemplate>    
    <FooterTemplate>         
        </channel>      
        </rss>    
    </FooterTemplate>
</asp:repeater>

It's as simple as that!

Tags:

.NET | Programming

Comments

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Copyright © 2009 Jesper Hess Nielsen. This work is licensed under the Creative Commons License.
Powered by BlogEngine.NET 1.5.0.7
Theme by Extensive SEO

About the author

A blog about me, R/C planes, .NET, Twitter and whatever else I feel like writing about.