Click here to Skip to main content
15,891,567 members
Articles / All Topics

RSS Feed

Rate me:
Please Sign up or sign in to vote.
4.43/5 (4 votes)
28 Sep 2016CPOL 5.2K   3  
RSS feed

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

Creating the Feed

C#
<code>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;
       }
   }</code>

MVC View

This simply references the above code and returns it as an Action Result.

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

        }
This article was originally posted at http://coopsblog.wales/blog/viewblog/RSS-Feed

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --