locked
Rss RRS feed

  • Question

  • User380413204 posted

    Hi all,

    I would like to have your thoughts on the following:

    In the Clubkit I have this Rss link. (points to an XML file somewhere on the server)

    What would be the best way to manage that?

    I have been playing around with RSSeditor but besides that I can't reach the FTP folder (via IIS) on my webserver like Visual studio can, it would also not be possible to edit the existing XML file.

    Thanks,

    Lex

    Wednesday, June 14, 2006 10:48 AM

All replies

  • User654902800 posted

    Skip the file, serve it dynamically like the news_list.aspx does.

    Sue hints at a real simple example of making a feed with a datalist here, she's reading XML too, but she mentions another approach here.

    And for more sophisticated feeds there is this cool thing  that I use here.

    Note either solution needs some fiddling around to make it pass the feed validator.

    Or you can make your own, this will get you started, if you can turn this into VB (easy) then you can figure out the rest of it.

            using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ClubSiteDB"].ConnectionString))
            {
                SqlCommand cmd = new SqlCommand();
                String query = "SELECT top 10 [id], [title], [description] FROM [Announcements] order by itemdate desc";
                cmd = new SqlCommand(query, con);
                SqlDataReader myReader;
                con.Open();
                myReader = cmd.ExecuteReader();
                while (myReader.Read())
                {
                   // build the items here, you know, append to a stringbuilder or something
                   // [item]        myReader.GetString(1),
                   // [description] HttpUtility.HtmlEncode(myReader.GetString(2)),
                   // [link]        "~/News_View.aspx?articleid=" + myReader.GetInt32(0).ToString(),
                }
                con.Close();
            }

    Thursday, June 15, 2006 2:34 AM
  • User380413204 posted

    Hi Mark,

    Looked  at the "Cool thing" , too complicated for me at this stage.

    But finally got the "other approach" working. Great stuff.

    I can publish "webbased" now.

    And once again thanks,

    Lex 

    Wednesday, June 21, 2006 5:46 PM
  • User-1876377467 posted

    Mr. Lunch,

      Thanks for the post.  I get an error message when I try to implement the 'other approach'.  I'm a beginner so I apologize if I should understand this error...  Thanks for any help you can give!

     The error says:

    Server Error in '/' Application.

    Parser Error

    Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

    Parser Error Message: Could not load type 'UberAspNet.RSS.NewsWire'.

    Source Error:

    Line 1:  <%@ Page Codebehind="News_Feed.aspx.vb" Inherits="UberAspNet.RSS.NewsWire" EnableViewState="false" %>
    Line 2:  <%@ OutputCache Duration="300" VaryByParam="none" %>
    

    Source File: /rss/news_feed2.aspx    Line: 1


    Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

    Here's my code:

    File one (news_feed2.aspx):

    <%@ Page Codebehind="News_Feed.aspx.vb" Inherits="UberAspNet.RSS.NewsWire" EnableViewState="false" %>

    <%@ OutputCache Duration="300" VaryByParam="none" %>

    File two (news_feed.aspx.vb):

    Imports System

    Imports System.Configuration

    Imports System.Data

    Imports System.Data.SqlClient

    Imports System.Text

    Imports System.Web

    Imports System.Xml

     

    Namespace UberAspNet.RSS

    Public Class NewsWire

    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", "YPC of Greater Des Moines News & Events Feed")

    objX.WriteElementString("link", "http://www.ypcdsm.com/rss/news_feed.aspx")

    objX.WriteElementString("description", "The latest news and events for YPC of Greater Des Moines")

    objX.WriteElementString("copyright", "(c) 2006, Young Professionals Connection of Greater Des Moines, All rights reserved.")

    objX.WriteElementString("ttl", "5")

    Dim objConnection As New SqlConnection(ConfigurationSettings.AppSettings("ClubSiteDB"))

    objConnection.Open()

    Dim sql As String = SelectCommand = "SELECT top 5 events.id, events.starttime, events.endtime, events.title, locations.title AS locationname FROM events LEFT OUTER JOIN locations ON events.location = locations.id WHERE (events.starttime > GETDATE()) ORDER BY events.starttime, events.id "

    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.ypcdsm.com/events_view.aspx?eventid=" + 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

    Saturday, November 4, 2006 8:53 PM
  • User523970105 posted

    The following code seems to be working for me:

     File RSS_Feed.aspx:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="RSS_Feed.aspx.cs" Inherits="RSS_Feed" EnableViewState="false" %>
    <%@ OutputCache Duration="10" VaryByParam="none" %>

    File RSS_Feed.aspx.cs:

    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Collections;
    using System.Text;
    using System.Web;
    using System.Xml;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class RSS_Feed : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Clear out the buffers and let the client know that this is XML
            Response.Clear();
            Response.ContentType = "application/rss+xml";

            // Create the XML object and write the header
            XmlTextWriter objX = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
            objX.WriteStartDocument();
            objX.WriteProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"rss.xsl\"");
            objX.WriteStartElement("rss");
            objX.WriteAttributeString("version", "2.0");
            objX.WriteStartElement("channel");
            objX.WriteElementString("title", "Your Title");
            objX.WriteElementString("link", "http://your.site.com/RSS_Feed.aspx");
            objX.WriteElementString("description", "The latest news from Your Site");
            objX.WriteElementString("ttl", "5");

            // Create and open the SQL database
            SqlConnection objConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ClubSiteDB"].ConnectionString);
            objConnection.Open();

            string sql = "SELECT TOP 10 title, description, id, itemdate FROM Announcements ORDER BY itemdate DESC";
            SqlCommand objCommand = new SqlCommand(sql, objConnection);
            SqlDataReader objReader = objCommand.ExecuteReader();
            while (objReader.Read())
            {
                objX.WriteStartElement("item");
                objX.WriteElementString("title", objReader.GetString(0));
                objX.WriteElementString("description", objReader.GetString(1));
                objX.WriteElementString("link", "http://your.site.com/News_View.aspx?Articleid=" + objReader.GetInt32(2).ToString());
                objX.WriteElementString("guid", "http://your.site.com/News_View.aspx?Articleid=" + objReader.GetInt32(2).ToString());
                objX.WriteElementString("pubDate", objReader.GetDateTime(3).ToString("R"));
                objX.WriteEndElement();
            }
            objReader.Close();
            objConnection.Close();

            objX.WriteEndElement();
            objX.WriteEndElement();
            objX.WriteEndDocument();
            objX.Flush();
            objX.Close();
            Response.End();
        }
    }

    And finally, file rss.xsl:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml"  />
    <xsl:template match="/">

    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
    <title><xsl:value-of select="rss/channel/title"/></title>
    <style>

    body {
     margin: 0px;
     padding: 0px;
     color: #000000;
     font-family: Arial, Helvetica;
     font-size: 12pt;
     background-color: #ffffff;
     color: #000000;
    }

    a:LINK {
     color: #666699;
     text-decoration: none;
    }

    a:ACTIVE {
     color: #ff0000;
    }

    a:VISITED {
     color: #000066;
     text-decoration: none;
    }

    a:HOVER {
     text-decoration: underline;
    }

    #Content {
     padding-top: 12px;
     padding-left: 35px;
     padding-right: 35px;
    }

    .rss {
     ;
     display: inline;
     background-color: orange;
     color: #ffffff;
     border: solid 2px black;
     padding: 5px;
     padding-top: 2px;
     padding-bottom: 2px;
     font-weight: bold;
     font-family: Arial, Helvetica;
     margin: 0px;
     font-size: 25pt;
     left: -15px;
     top: -5px;
    }

    h1,h2,h4 {
     color: #666666;
     font-weight: bold;
     font-family: Arial, Arial, Helvetica;
     margin: 0px;
     font-size: 25pt;
    }

    h2 {
     font-size: 16pt;
     margin-left: 16px;
    }

    h4 {
     font-size: 11pt;
     font-family: Arial, Helvetica;
    }

    #ContentDescription {
     margin: 35px;
     margin-bottom: 30px;
     color: #000000;
     border-color: #dddddd;
     border-width: 2px;
     border-style: solid;
     padding-left: 5px;
     padding-right: 5px;
     padding-bottom: 5px;
    }

    #ItemList {
     list-style-type: circle;
     color: #666666;
    }

    .ItemListItem {
     padding-bottom: 8px;
    }

    .ItemListItemDetails {
     font-family: Arial, Helvetica;
     font-size: 8pt;
     color: #333333;
    }

    </style>
    </head>
    <body xmlns="http://www.w3.org/1999/xhtml">
     <div id="ContentDescription">
      <div class="rss">RSS</div>
      <h1>What is RSS?</h1>
      <p>
          This page is an RSS syndication feed. Simply put, it's an alternate way for you to be
          notified when news items are posted on the web page.
        </p>
        <p>
          To use the RSS feed, you need to start by downloading an RSS reader (otherwise known as
          an RSS Aggregator).  One such reader is SharpReader, which can be downloaded from
          <a target="_blank" href="http://www.sharpreader.net">www.sharpreader.net</a>.
        </p>
        <p>
          After downloading and installing the reader, copy the URL from this page into the reader
          where it requests a URL.
        </p>
        <p>
          <em>Please note that this feed currently only contains news items.  All other website
          changes (calendar items, new photos, etc.) are not included, so please visit the website
          often to view those items.</em>
        </p>
      <p>
         If you would like additional information regarding RSS, please visit
         <a target="_blank" href="http://en.wikipedia.org/wiki/RSS_%28file_format%29">Wikipedia</a>
         for an explanation.
      </p>
     </div>
     
     <div id="Content">
      <h1><xsl:value-of select="rss/channel/title"/></h1>
      
      <ol id="ItemList">
       <xsl:for-each select="rss/channel/item">      
        <li class="ItemListItem">
         <h4><a><xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute><xsl:value-of select="title"/></a></h4>
         <div class="ItemListItemDetails">
          Published <xsl:value-of select="pubDate"/>
         </div>
        </li>
       </xsl:for-each>
      </ol>
     </div>
     
    </body>
    </html>

    </xsl:template>
    </xsl:stylesheet>

    Monday, November 6, 2006 10:41 AM
  • User523970105 posted

    Sorry, shouldn't have underlined the file names in the above.  It makes them hard to read.

    The three file names (in order of appearance above) are:

    • RSS_Feed.aspx
    • RSS_Feed.aspx.cs
    • rss.xsl
    Monday, November 6, 2006 10:46 AM
  • User-1815760274 posted

    I'm relatively new to RSS feeds. I created these files in my Club project, rebuilt, and loaded the files to my site.

    1.To get the RSS_Feed.aspx part to compile, I had to add an empty html skeleton. Is this right?

     2. How do I enable this so the RSS feed indicator comes on in IE7?

    Richard

    Saturday, December 23, 2006 2:26 AM
  • User523970105 posted

    I'm relatively new to RSS feeds. I created these files in my Club project, rebuilt, and loaded the files to my site.

    1.To get the RSS_Feed.aspx part to compile, I had to add an empty html skeleton. Is this right?

     2. How do I enable this so the RSS feed indicator comes on in IE7?

    Richard

    1.  Hmmm... I didn't have to add an html skeleton.  My RSS_Feed.aspx contains only what is listed above.

    2.  I haven't looked into IE7's RSS reader at yet, but I intent to as soon as the holidays are over.  If I figure anything out I'll post it.

    Thursday, December 28, 2006 5:59 PM
  • User-1563988197 posted

    http://blogs.msdn.com/rssteam/archive/2005/08/03/446904.aspx

    1    <html>
    2      <head>
    3        <link rel="alternate" type="application/rss+xml" title="your feed title here" href="http://www.company.com/feedurl.rss">
    4      </head>
    5    <body>
    
     
    Friday, December 29, 2006 3:12 PM
  • User-1563988197 posted

    Sue hints at a real simple example of making a feed with a datalist here, she's reading XML too, but she mentions another approach here.

     

    Looks like thats for .NET 1.0 or 1.1 since it says "CodeBehind" and not "CodeFile".

     

    Have you seen any other articles?

    Friday, December 29, 2006 3:14 PM
  • User-1815760274 posted

    Actually, this goes in the Default.master. I was talking of RSS_Feed.aspx. I get a fatal error saying I need an HTML directive. Obviously, I have a structural problem.

     A related question - how does the RSS_Feed.aspx link through the rss.xsl which should create the HTML dynamically. I've missed something here and I believe it will answer the other issue also.

     Richard

    Monday, January 15, 2007 9:03 PM
  • User-636165704 posted

    I have used this but it doesn't seem to be working all that nicely.

    I have added a querystring which I use to identify the specific feed that I want to view. Then these quesrystring paramaters are passed into SQL Server to extract the data.

    I have however picked up that on (if I'm not msitaken only on) IE6 browsers it asks to download the aspx file that contains that feed. If I download the file I get the feed but it doesn't display the feed in the browser. This works in IE7, haven't tried it in other browsers!

    I really need this feed to be displayed in the browser and for it to work!!!

    Any ideas to what maybe wrong???

    The code section I used to get the data for the rss file returned looks like this:

            '' Create and open the SQL database
            Dim objConnection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("constring").ConnectionString)
            objConnection.Open()
    
            Dim sql As String = "RSS_READ"
            Dim objCommand As New SqlCommand
            objCommand.CommandText = sql
            objCommand.CommandType = CommandType.StoredProcedure
            objCommand.Connection = objConnection
            objCommand.Parameters.AddWithValue("@feed", Request.QueryString("feed"))
    
            Dim user As Integer = Request.QueryString("user")
            If user = Nothing Then
                user = 0
            End If
    
            objCommand.Parameters.AddWithValue("@user", user)

     Is there anything else that I should include to get this to work?

    The html Looks like this:

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="rss_feed.aspx.vb" Inherits="rss_feed" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
        </div>
        </form>
    </body>
    </html>
     Unfortunately I have to add everything below the <@Page> decleration as VB/ASP doesn't want to compile the page if it isn't there. I'm coding in VS2005 using .Net 2 and SQL Server 2005
    Wednesday, May 2, 2007 10:11 AM
  • User1140699731 posted

    hi typhoid,

     thanks for posting the code. i used it on the site i'm building but there's one problem: IE7.

     i tested in firefox and opera. both render the feed fine.

     but, IE7 renders as plain text. no line breaks or anything. just a big clump of plain text.

     any suggestions?

    all the best,

    steve
     


     

    Friday, May 4, 2007 11:19 PM
  • User1140699731 posted

    you're all going to think i'm crazy but it seems to be working now.

    while messing with the code (i tried to insert some line breaks to break up the big clump of plain text), i got an error message.

    after i did a few control z's to remove the line break stuff, i re-ran your code and now IE7 likes it. renders it just like it's supposed to.

    go figure.

    anyone know why IE7 didn't accept it right away but firefox and opera had no problems? 



     

    Saturday, May 5, 2007 2:07 PM
  • User-2054142495 posted

     Looking at whats been written here but still seem to be having problems!

    Not getting any errors from my code or in VS! Can anybody please assist and tell me why my code is not working and were I'm going wrong?

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="incFeed.aspx.vb" Inherits="aspx_pages_rss_incFeed" %>
    <%@ OutputCache Duration="200" VaryByParam="none" %>


        <asp:Repeater id="rptRSS" runat="server">
      <HeaderTemplate>
        <rss version="2.0">
          <channel>
            <title>My News!</title>
            <link> http://www.xxxxxxxxx/Headlines/ </link>
            <description>
              This is the syndication feed.
            </description>
      </HeaderTemplate>

      <ItemTemplate>
            <item>
              <title><%# FormatForXML(DataBinder.Eval(Container.DataItem, "IncTitle")) %></title>
              <description>
                 <%# FormatForXML(DataBinder.Eval(Container.DataItem, "IncLocation")) %>
              </description>
              <link> http://www.xxxxxxxxx/aspx/pages/myfolder/myDetail.aspx?id=<%#DataBinder.Eval(Container.DataItem, "ID")%></link>      
              <pubDate>
     <%#String.Format("{0:R}", DataBinder.Eval(Container.DataItem, "IncDate"))%>
               </pubDate>
            </item>
      </ItemTemplate>

      <FooterTemplate>
          </channel>
        </rss>  
      </FooterTemplate>
    </asp:Repeater>

     

     

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

    Partial Class aspx_pages_rss_incFeed
        Inherits System.Web.UI.Page
        Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
            ' Connect to the Database
            Dim myConnection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("myDB").ConnectionString)
            ' Retrieve the SQL query results and bind it to the Repeater
            Dim SQL_QUERY As String = ("SELECT TOP 5 ID, IncTitle, " + ("IncLocation, IncDate " + "FROM table1 ORDER BY IncDate DESC"))
            Dim myCommand As SqlCommand = New SqlCommand(SQL_QUERY, myConnection)
            ' bind the results to the Repeater
            myConnection.Open()
            rptRSS.DataSource = myCommand.ExecuteReader
            rptRSS.DataBind()
            myConnection.Close()
        End Sub

        Protected Function FormatForXML(ByVal input As Object) As String
            Dim data As String = input.ToString
            ' cast the input to a string
            ' replace those characters disallowed in XML documents
            data = data.Replace("&", "&")
            data = data.Replace("\""", "")
            data = data.Replace("'", "'")
            data = data.Replace("<", "<")
            data = data.Replace(">", ">")
            Return data
        End Function
    End Class

    Tuesday, September 30, 2008 12:29 PM
  • User1871132334 posted

    A little late, but I wanted to share that it did not work in IE7 from the local server, but did when it was on the live server...

    Wednesday, April 15, 2009 5:39 PM