I created a WebPart where RSS feed form a SharePoint Blog Posts list was consumed and modified to display, the two recently updated blog posts. Also, the post opens up in a new window on Click of the Post title.
"rss_text" in the below code will return your feed (two recently updated posts).
So here is the code to extract data from feed.
First,
1. Create a WebPart.
2. In CreateChildControls Call the Below method DisplayRSS() and pass the Posts list Rss Feed url( Get the RSS feed link from "View RSS" option in the Posts lists).
protected string DisplayRSS(string ListRssUrl)
{
try
{
string rss_text = "";
string title = "";
string link = "";
string description = "";
XPathDocument doc = new XPathDocument(ListRssUrl);
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator items = nav.Select("//item");
int items_to_show = 2;
int count = 0;
while (items.MoveNext() && count < items_to_show)
{
XPathNavigator navCurrent = items.Current;
try
{
title = navCurrent.SelectSingleNode("title").InnerXml;
link = navCurrent.SelectSingleNode("link").InnerXml;
description = navCurrent.SelectSingleNode("description").InnerXml;
}
catch{ }
CleanUp(ref title,ref description); // Calling a FeedClean Function
if (description != "")
{
description = "- " + description;
description += "...";
}
rss_text += "<a href='" + link + "' target='_blank'>" + title + "</a> " + description;
if (count < items_to_show - 1)
rss_text += "<br/><br/>";
rss_text += "</div>";
count++;
}
return rss_text;
}
catch
{ }
}
protected void CleanUp(ref string title,ref string description)
{
title = title.Replace("\n", " ");
title = title.Replace("\r", " ");
description = description.Replace("<", "<");
description = description.Replace(">", ">");
description = Regex.Replace(hover_description, @"<(.\n)*?>", string.Empty); // To Remove all the html tags from the RSS feed.
title = title.Trim();
description = description.Trim();
}
See another example at my new website
Custom Rss feed webpart in Sharepoint 2010
Related Post :
Display Approved Blog Posts
Custom Rss Feed WebPart
Posted by
Isha Attlee
Labels:
SharePoint Programming
Subscribe to:
Post Comments (Atom)
Disclaimer
This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at sharepointprogrammingblogger@gmail.com .
Copyright (c) 2010 @ myshaepointwork.blogspot.com. All rights are reserved.Do Not Copy.
Copyright (c) 2010 @ myshaepointwork.blogspot.com. All rights are reserved.Do Not Copy.
1 comments:
Are you a Sharepoint developer? if yes then Why not Sell your webparts
visit Submit Your WebPart
Post a Comment