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/")));
feed.LastUpdatedTime = DateTimeOffset.Now;
feed.Language = "en-us";
feed.Id = "http://someuri.com/feed.rss";
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"); // 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.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
SyndicationLink.CreateMediaEnclosureLink(new Uri("http://someuri.com/podcasts/somepodcast.wmv"), type, length));
// Add this item to the collection (this create new item, could be in a loop, perhaps – reading from a database?)
// 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.