c# - 使用 ASP.Net 获取和显示 RSS 提要

标签 c# javascript html asp.net rss

我需要阅读并在我的网页中显示此提要。

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

使用 c# net 2。

我试过这个教程:

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

但错误是:

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

为什么?

下面是我的代码。

如果您能在解决这个问题时给我任何帮助,我将不胜感激。

<%@ 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;
        }
    }
}

最佳答案

如何使用如下所示的纯 Javascript/jQuery 解决方案:

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"/>

工作 fiddle

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

描述

上面的代码只是对提要进行了 json 调用,在成功函数内它循环结果并使用 jQuery 附加输出提要的内容。

关于c# - 使用 ASP.Net 获取和显示 RSS 提要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24572527/

相关文章:

html - 如何使顶部溢出以使反向滚动工作?

c# - 我应该如何将我的商业模式与我的观点联系起来?

c# - Entity Framework 4.3 代码优先数据库命名

c# - ASP Repeater 没有以正确的顺序显示数据

javascript - if 语句 javascript on select 标签

Javascript 在从 iOS 输入和离开选择标签时显示/隐藏固定元素

c# - 如何使用 EventReceiver 以编程方式更改 SharePoint 2010 中的页面名称和 url

javascript - jquery show hide 不能正常工作

javascript - jQuery 插件未应用于选择元素

JavaScript 非正则表达式替换