I am trying to add posts from a wordpress blog to my site, I am trying to to use SyndicationFeed class along with XmlReader using the following code
var reader = XmlReader.Create("http://nycphotographer.wordpress.com/feed/");
var feed = SyndicationFeed.Load<SyndicationFeed>(reader);
lblBlogPost.Text = "Latest posts from " + feed.Title.Text + Environment.NewLine;
foreach (var item in feed.Items)
{
lblBlogPost.Text += item.Title.Text + Environment.NewLine;
lblBlogPost.Text += item.Content + Environment.NewLine;
}
and then when I try to read the feed item’s content (which is CDATA encoded) I get null in the content section.
Then I tried to follow SyndicationItem.Content is Null but the problem is that the answer provided in this SO post is giving me an error of
'System.Collections.ObjectModel.Collection<string>' to 'string'
.
please someone point me in the right direction.
**EDIT: ** as pointed out by @Sapster the full error statement is as follows
Cannot implicitly convert type 'System.Collections.ObjectModel.Collection<string>' to 'string'
Summary helped in my case
I’m not sure if these are “answers” or rather just points of note, but too much info to put as comments so hopefully something here helps you!
According to http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fnycphotographer.wordpress.com%2Ffeed%2F your feed is valid but warns “…interoperability with the widest range of feed readers could be improved…” and provides advice re these issues.
There are known issues with WordPress feeds generally – http://validator.w3.org/feed/docs/error/WPBlankLine.html
I have personally seen instances with WP feeds (just yesterday, in fact!) where a particular reader (in this case, FF) will fail to apply a default style to the (otherwise un-styled) feed most of the time, but not all of the time (eg ~5 of 20 refreshes display properly), which suggests to me that WP is emitting inconsistent output.
So – I’d recommend pointing your code at a “known good” feed to verify that the problem is not server-side.