如何在保存Rss Feed的同时排除图像数据库并需要在页面中显示完整的Feed描述

时间:2012-02-09 10:02:06

标签: c# asp.net rss

当我在数据库中保存RssFeed所有字段都保存像链接,Id等,但来到描述它只保存smalldescription直到图像Src来和停止那里。我只是想忽略图像,需要保存完整描述和显示在我的页面中。我在Repeater控件中显示Rss Feed我将在此处发布我的代码,并提前感谢

aspx:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="RSSFeed.aspx.cs" Inherits="RSSFeed" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<div class="blog_bg">
        <%--  <asp:Label ID="lblBlogOutput" runat="server"></asp:Label>
        <asp:Label ID="Label1" runat="server"></asp:Label>
        <asp:Label ID="Label2" runat="server"></asp:Label>--%>
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <div>
                    <asp:HyperLink ID="TitleHyperLink" runat="server" Text='<%#Eval("Title") %>' NavigateUrl='<%#Eval("Link") %>'></asp:HyperLink>
                    <br />
                    <p>
                        <asp:Label ID="DescriptionLabel" runat="server" Text='<%#Eval("Description") %>'></asp:Label>
                        &nbsp;&nbsp;<%--</br><asp:HyperLink ID="MoreHyperLink" runat="server">See More...</asp:HyperLink></p>--%>
                    <div id="divdesc">
                    <asp:Label ID="PublishedLabel" runat="server" Text='<%#Eval("Published") %>'></asp:Label>
                        <%--<asp:Label ID="Label1" runat="server" Text='<%#Eval("SmallDescription") %>'></asp:Label>--%>
                        &nbsp;&nbsp;<%--<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/NewsFeedinfo.aspx?RssId={0}">See More...</asp:HyperLink>--%>
                        <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# "NewsFeedinfo.aspx?RssId=" + Eval("RssID") %>' >See More...</asp:HyperLink>

                        </p>
                    </div>
                </div>
            </ItemTemplate>
        </asp:Repeater>
    </div>
</asp:Content>

aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Data;

public partial class RSSFeed : System.Web.UI.Page
{
    RssDC rssDC = new RssDC();
    RssBAL rssBAL = new RssBAL();

    protected void Page_Load(object sender, EventArgs e)
    {

        BlogFeeds("http://rss.cnn.com/rss/edition_americas.rss", 3);
        BlogFeeds("http://feeds.bbci.co.uk/news/rss.xml?edition=int#", 3);
        BlogFeeds("http://feeds.reuters.com/reuters/Election2012", 3);

        fillRssFeeds();

    }



    private void fillRssFeeds()
    {
        DataSet ds = new DataSet();
        ds = rssBAL.GetRssFeeds(rssDC);

        Repeater1.DataSource = ds;
        Repeater1.DataBind();
    }
    protected void BlogFeeds(string url, int count)
    {

        try
        {

            RssDC rssDC = new RssDC();
            XmlDocument xmldoc = new XmlDocument();
            XmlNodeList items = default(XmlNodeList);
            xmldoc.Load(url);
            items = xmldoc.SelectNodes("/rss/channel/item");
            int i = 0;
            // use XPath to get only items

            foreach (XmlNode item1 in items)
            {
                int currentIterationIndex = 0;
                foreach (XmlNode node1 in item1.ChildNodes)
                {
                    if (currentIterationIndex == count - 1)
                    {
                        continue;
                    }


                    if (node1.Name == "title")
                    {
                        rssDC.Title = node1.InnerText;
                    }
                    else if (node1.Name == "link")
                    {
                        rssDC.Link = node1.InnerText;
                    }
                    else if (node1.Name == "guid")
                    {
                        rssDC.RSS_ID = node1.InnerText;
                    }
                    else if (node1.Name == "description")
                    {
                        rssDC.Description = node1.InnerText;
                    }
                    else if (node1.Name == "pubDate")
                    {
                        rssDC.DatePublished = node1.InnerText;


                    }
                    currentIterationIndex += 1;


                }
                rssDC = RssBAL.AddRssFeed(rssDC);
                i++;

                if (i == 3)
                    break;

            }



        }
        catch (Exception eax)
        {
            //return;
        }

        //return rssFeedList;
        //Repeater1.DataSource = rssFeedList;
        //Repeater1.DataBind();
    }
} 

1 个答案:

答案 0 :(得分:0)

删除asp:Label并使用&lt;%#Eval(“Description”)%&gt;没有它。