Using .NET 3.5 to create a Podcast feed

I’m mainly writing this to maybe save some other poor soul from wasting hours and hours to find something, in hindsight, seems a little bit obvious. As discussed, a Podcast is really just the concept of using RSS to publish multimedia clips (sound files or video files).

However, for most podcatchers to understand a feed as a podcast, it only looks for an <enclosure/> tag in the RSS feed. How do you go about creating one of those? Wellsir, let me save you a few hours. Since .NET 3.5 is so new, there is not much written up on this, so let me try to break it down.

First – add a reference to System.ServiceModel (3.0) and System.ServiceModel.Web (3.5). Most everything you need is in there. For creating an RSS for content that you want to post – you basically create an instance of SyndicationFeed, set some properties – and the RSS feed items are basically of-type SyndicationItem. So create a collection of those, assign them to the feed – then "save" the feed to a physical file:

    // Create the feed itself

    SyndicationFeed feed = new SyndicationFeed();

    feed.Title = new System.ServiceModel.Syndication.TextSyndicationContent("Title");

    feed.Links.Add(new System.ServiceModel.Syndication.SyndicationLink(new Uri("http://someUri.com/&quot;)));

    feed.LastUpdatedTime = DateTimeOffset.Now;

    feed.Language = "en-us";

    feed.Id = "http://someuri.com/feed.rss&quot;;

    feed.Generator = "My .NET code!";

    feed.Description = new System.ServiceModel.Syndication.TextSyndicationContent("Description goes here");

    feed.Copyright = new System.ServiceModel.Syndication.TextSyndicationContent("Copyright © 2008, somebody");

    feed.ImageUrl = new Uri("http://someuri.com/images/someimage.jpg&quot;); // Images are typically 300×300 pixels

 

    // Create a collection for all of the feed items

    List<SyndicationItem> items = new List<SyndicationItem>();

 

    // Create a new item

    SyndicationItem item = new SyndicationItem();

    item.Categories.Add(new SyndicationCategory("Category1"));

    item.Title = new TextSyndicationContent("Podcast title goes here");

    item.Summary = new TextSyndicationContent("Podcast description goes here (article content)");

    item.PublishDate = DateTimeOffset.Now;

 

    long length = 123456; // the size of the attachment, in bytes

    string type = "application/x-ms-wmv"; // or other valid content-type

    item.Links.Add(

        SyndicationLink.CreateMediaEnclosureLink(new Uri("http://someuri.com/podcasts/somepodcast.wmv&quot;), type, length));

 

    // Add this item to the collection (this create new item, could be in a loop, perhaps – reading from a database?)

    items.Add(item);

 

    // Assign the collection to the feed

    feed.Items = items;

 

    //feed.SaveAsRss20(writer); // Actually save this as an RSS 2.0 feed file

That’s basically it – you do a SyndicationLink.CreateMediaEnclosureLink() to create an entry that will work with a typically podcatcher.

And while I’m at it, I was a little annoyed that this was so difficult to do in todays day and age. What I mean is, I also looked at other podcast hosters – they all either just didn’t work, errored out, were misleading – or cost money. So then I got thinking – hey, since a podcast is really nothing more than an RSS feed that has an item that has an enclosure, sure spaces.live.com or other blog sites give you this simple ability? But no! I found I pretty much HAD to write my own code for this (again, without paying for some software) – and that’s crazy! So I did start fleshing out http://www.robertseder.com/ and I did start writing an app that let’s me manage my podcasts – and using code similar to the above, I generate this feed file: http://www.robertseder.com/Podcast.rss which has my very first podcast in it.

I think I may try to componentize this, what should be, easy functionality – and I’ll post it up here when done.

Posted in .NET 3.5, Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives
Categories

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 5 other followers

%d bloggers like this: