Hamamelis
Hamamelis

Reputation: 2115

Fetch and Display RSS Feeds using ASP.Net

I need read and display this feed in my web page.

http://picasaweb.google.com/data/feed/base/user/ComunidadMexicana?alt=rss&kind=album&hl=it&access=public

using c# net 2.

And I tried this tutorial:

http://www.aspsnippets.com/Articles/Fetch-and-Display-RSS-Feeds-using-ASP.Net.aspx

But the error is:

A column named 'link' already belongs to this DataTable: 
cannot set a nested table name to the same name.

Why?

My code below.

I would greatly appreciate any help you can give me in working this problem.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="FeedPicasa_Default" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Repeater ID="rssRepeater" runat="server">
            <ItemTemplate>
                <table style="border: solid 1px black; width: 500px; font-family: Arial">
                    <tr>
                        <td style="font-weight: bold">
                            <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#Eval("link")%>' Text='<%#Eval("title")%>'></asp:HyperLink>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <hr />
                        </td>
                    </tr>
                    <tr>
                        <td style="background-color: #C2D69B">
                            <asp:Label ID="Label1" runat="server" Text='<%#Eval("description")%>'></asp:Label>
                        </td>
                    </tr>
                </table>
                <br />
            </ItemTemplate>
        </asp:Repeater>
    </div>
    </form>
</body>
</html>


using System;
using System.Net;
using System.Xml;
using System.Data;

public partial class FeedPicasa_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        GetRSS();
    }

    private void GetRSS()
    {
        //Create a WebRequest
        WebRequest rssReq =
        WebRequest.Create("http://picasaweb.google.com/data/feed/base/user/ComunidadMexicana?alt=rss&kind=album&hl=it&access=public");

        //Create a Proxy
        WebProxy px = new WebProxy("http://picasaweb.google.com/data/feed/base/user/ComunidadMexicana?alt=rss&kind=album&hl=it&access=public", true);

        //Assign the proxy to the WebRequest
        rssReq.Proxy = px;

        //Set the timeout in Seconds for the WebRequest
        rssReq.Timeout = 5000;
        try
        {
            //Get the WebResponse
            WebResponse rep = rssReq.GetResponse();

            //Read the Response in a XMLTextReader
            XmlTextReader xtr = new XmlTextReader(rep.GetResponseStream());

            //Create a new DataSet
            DataSet ds = new DataSet();

            //Read the Response into the DataSet
            ds.ReadXml(xtr);

            //Bind the Results to the Repeater
            rssRepeater.DataSource = ds.Tables[2];
            rssRepeater.DataBind();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}

Upvotes: 1

Views: 2729

Answers (1)

hutchonoid
hutchonoid

Reputation: 33305

How about using a pure Javascript/jQuery solution as follows:

Javascript

$(function(){
        url = 'http://picasaweb.google.com/data/feed/base/user/ComunidadMexicana?alt=rss&kind=album&hl=it&access=public';
        $.ajax({
        type: "GET",
        url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&callback=?&q=' + encodeURIComponent(url),
        dataType: 'json',
        error: function(){
            alert('Unable to load feed, Incorrect path or invalid feed');
        },
        success: function(xml){
            values = xml.responseData.feed.entries;

            $.each(values, function( index, value ) {
              $('#myFeed').append(value.content);
                $('#myFeed').append('<br/>');
            });
        }
    });
    });

Html

<div id="myFeed"/>

Working fiddle

http://jsfiddle.net/5EtnX/1/

Description

The above simply makes a json call to the feed, inside the success function it loops the results and outputs the feed's content with a jQuery append.

Upvotes: 2

Related Questions