RSS Feed
This is a simple code, which I have used to create my own RSS feed


Creating the Feed

public class RSSFeed
{

public static List CreateFeed()
{
var items = new List();
var blogs = Models.Blog.Queries.BlogQuery.RenderActiveList();
foreach(var blog in blogs)
{


var item = new SyndicationItem()
{
Id = Guid.NewGuid().ToString(),
Title = new TextSyndicationContent(blog.Title),
Content = = new TextSyndicationContent(blog.Body, TextSyndicationContentKind.Html),
PublishDate = (DateTime)blog.PublishDate,
LastUpdatedTime = (DateTime)blog.UpdateDate,
};
item.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(String.Format("http://coopsblog.wales/blog/viewblog/{0}",blog.Name))));//Nothing alternate about it. It is the MAIN link for the item.
//This is so code project can see it!http://www.codeproject.com/script/Articles/BlogFeed.aspx
//This is simply, just so Code project can see my RSS feeds
item.Categories.Add(new SyndicationCategory("CodeProject"));

//Add my tags as categories
string[] tags = blog.Tags.Split(',');
foreach (string tag in tags)
item.Categories.Add(new SyndicationCategory(tag));

items.Add(item);

}

return items;
}


public static List CreateFeedCP()
{
var items = new List();
var blogs = Models.Blog.Queries.BlogQuery.RenderActiveList();


return blogs;
}
}


MVC view
This simply references the above code and returns it as a Action Result

[HttpGet]
public ActionResult RssFeed()
{
return new RssFeed("application/rss+xml", "Coopsblog", String.Format("A RSS feed to my blogs"),PrimaryCore.RSSFeed.CreateFeed());

}
Created: 28/09/2016 Total Comment: 0

Comments

(Not Displayed)
Human validation
Enter 2201 number, before submitting to confirm your human
[Home] [All Blogs] [Contact] [Me]