I've successfully created an ASP.NET RSS feed reader that I am using with Tumblr for a website. It works in that it grabs the most recent 3 posts. I have 6 posts to test and I deleted 3 but my reader is not showing the original three posts. It keeps showing the last 3 that were deleted. I have put the RSS in the browser for Tumblr and it shows correctly but my reader keeps showing the three posts that were deleted. I tried clearing cache and changing browsers but I still get the deleted posts in my feed. Here's the code I am using below:
Frontend Code:
<asp:GridView ID="gvRssLI" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<div>
<h3><%#Eval("Title") %></h3>
</div>
<div>
<%#Eval("PublishDate" , "{0:d}") %>
</div>
<div> </div>
<div align="right">
<a href='<%#Eval("Link") %>' target="_blank">Read More...</a>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code-behind Code:
private void PopulateRssFeed()
{
string rssFeedUrl = ConfigurationManager.AppSettings["RssFeedUrl"];
List<Feeds> feeds = new List<Feeds>();
XDocument xDoc = XDocument.Load(rssFeedUrl);
var items = (from x in xDoc.Descendants("item").Take(3)
select new
{
title = x.Element("title").Value,
link = x.Element("link").Value,
pubDate = x.Element("pubDate").Value,
});
if (items != null)
{
feeds.AddRange(items.Select(i => new Feeds
{
Title = i.title,
Link = i.link,
PublishDate = i.pubDate,
}));
}
gvRssLI.DataSource = feeds;
gvRssLI.AutoGenerateColumns = false;
gvRssLI.DataBind();
}
I tested your code and it works. The feed is displayed correctly. It seems Tumblr has long cache times. But as you say very few info can be found on that subject, the only useful hint was this url.
https://twitter.com/fromedome/status/237250951889698816
But did you know you can make strongly typed GridViews? You can use ItemType
in the GridView and then you have access to the Class properties with Item
. This helps with type-safety since the Item
is already the correct datatype. You have to modify YourNameSpace.Feeds
to your correct namespace.
<asp:GridView ID="gvRssLI" runat="server" ItemType="YourNameSpace.Feeds">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<div>
<h3><%# Item.Title %></h3>
</div>
<div>
<%# Item.PublishDate.ToLongDateString() %>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Note: you can also use a dedicated library to read RSS feeds, like https://github.com/codehollow/FeedReader