Derik Whittaker

Syndication

News


Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Generate your own RSS feed with Argotic

Adding an RSS (Really Simple Syndication) feed to your website has never been easier.  When trying to find a way to add an RSS feed to Dimecasts.net I first thought of just hand rolling my own RSS document, but that seemed like too much work.  After a bit of searching and asking on Twitter I was pointed to the open source .Net library called Argotic

In this post we will review the following steps needed to add a feed to your site.

  1. Creating the xml (rss feed) document for publication
  2. Creating an access point for the feed
  3. Adding the feed to your site
  4. Publishing your feed via Feedburner

Creating the xml (rss feed) document for publicationReferences
Setting up a feed with Argotic could not be easier, you basically just need to import the correct libraries.   After you have imported the correct libraries simply add a using statement for using Argotic.Syndication.  Finally you start coding. Below is the code I used (modified for this post) to create my feed.

public XDocument GenerateRSSFeed()
{
    var rssRepository = ObjectFactory.GetInstance();
    var items = rssRepository.GenerateRSSItems();

    var rssFeed = new RssFeed( "Main RSS Feed for DimeCasts.Net" );
    var rssChannel = new RssChannel( new Uri( "http://www.dimecasts.net" ), "Title", "Desc" );

    foreach ( var item in items )
    {
        var rssItem = new RssItem
                          {
                              Author = "Your name here",
                              Title = item.Title,
                              Link = new Uri( item.Link),
                              Guid = new RssGuid(item.Link),
                              Description = item.Description,
                              PublicationDate = item.PublishDate
                          };
        rssChannel.AddItem( rssItem );
    }

    rssFeed.Channel = rssChannel;


    return XDocument.Parse( rssFeed.CreateNavigator().OuterXml.ToString() );
   
}

Creating an access point for the feed
In order to allow people to know about your feed, you need to create an access point.  This could be something as simple as creating a static .xml document and placing it on your website.  However, you will more than likely want to make the document dynamic based on the content of your site. I found the simplest way to create the access point is to create a .aspx page and change the content type from html to "text/xml". 

// get the XML data/document
var feeds = new Feeds();

// Need to modify the Response type
Response.Clear();
Response.ContentType = "text/xml";

StreamWriter streamWriter = new StreamWriter( Response.OutputStream, Encoding.UTF8 );

// Make the call here to get the feed an write it out to the stream
streamWriter.Write( feeds.GenerateRSSFeed() );
streamWriter.Flush();

Response.End();
// Put this code here in your html part of the page.  This will cache the output for a given number
// of seconds
<%@ OutputCache Duration="600" VaryByParam="none" %>

Adding the feed to your site
In order to let the world know you have a feed, you need to expose it in your html documents.  For me, I wanted every page on the site to expose this so I added it to my mast page.  The code below shows how to add the pointer in your html page.   RSSIcon

After you have added the reference to your html page you should see the RSS feed icon on your URL bar in your browser.  The image to the right is of the DimeCasts site when being viewed in firefox

link title="[Your title here]" href="http://www.yourdomain.com/[rssfilehere]" type="application/rss+xml" rel="alternate" 

Publishing your feed via Feedburner
Now that you have gone through the pain of setting up your feed, I would suggest you syndicate your feed and use a tracking service like Feedburner.com.  One nice feature of feedburner is it allows you to track who is subscribing to your feed.

Well, I hope this helps someone.

Till next time,

[----- Remember to check out DimeCasts.Net -----]


Posted 06-10-2008 7:38 AM by Derik Whittaker

[Advertisement]

Comments

Michael Paladino wrote re: Generate your own RSS feed with Argotic
on 06-14-2008 10:37 PM

Good post.  Argotic looks cool.

One small issue though.  Shouldn't the tag in your master page point to the FeedBurner link rather than your custom link to ensure that all subscribers get tracked?

Derik Whittaker wrote re: Generate your own RSS feed with Argotic
on 06-15-2008 8:31 AM

@Michael,

From what i know, the tag on your page needs to be your own rss that way both Feedburner and others can subscribe.  The only way feedburner works is if someone subscribes via that service.

DotNetKicks.com wrote Generate your own RSS feed with Argotic
on 06-17-2008 1:13 PM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Christopher Steen wrote Link Listing - June 17, 2008
on 06-19-2008 12:04 AM

MSBuild MSBuild Reserved Properties [Via: Sayed Ibrahim Hashimi ] Sharepoint Adding Copy and Paste...

Christopher Steen wrote Link Listing - June 17, 2008
on 06-19-2008 12:05 AM

Link Listing - June 17, 2008

Brian Kuhn wrote re: Generate your own RSS feed with Argotic
on 06-27-2008 11:25 AM

I am glad that you have found my framework useful. Support for common scenarios like hosting an endpoint for a dynamic syndication feed is planned for the 2008.1.0.0 release using an IHttpHandler implementation.

Zolpidem. wrote Cheap zolpidem.
on 07-24-2008 10:38 PM

Zolpidem fedex. Zolpidem eszopiclone indications. Zolpidem.

Jay Smith » Generate your own RSS feed with WCF: Syndication wrote Jay Smith &raquo; Generate your own RSS feed with WCF: Syndication
on 09-03-2008 10:48 PM

Pingback from  Jay Smith &raquo; Generate your own RSS feed with WCF: Syndication

Jay Smith wrote Generate your own RSS feed with WCF: Syndication
on 10-27-2008 9:41 PM

Generate your own RSS feed with WCF: Syndication

Jay Smith wrote Generate your own RSS feed with WCF: Syndication
on 10-28-2008 11:15 PM

Generate your own RSS feed with WCF: Syndication

Pharmd569 wrote re: Generate your own RSS feed with Argotic
on 08-02-2009 2:02 PM

Very nice site!

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)