posted on 8:16 PM
Rob Howard asked how other people were doing RSS feeds, well this has been an issue for me recently, where I had to generate RSS feeds for existing objects. I used a little collection of classes to do this which I've uploaded here, here's a quick example of how I'm currenlty using these (names removed to protect the innocent) - note, these are not EXACT Rss, I added one field, xsdDate, 'cos I needed this for a transform (doesn't break readers having this extra bit though!), I'll update this later with a bit more info on these...essentially it passes through the items in an object (badly) named ItemFeedStruct and creates an entry for each one...doing a ToString() then gives me the complete RSS feed for this. Note, I did not write the RSS Classes originally, but I can't find the link to the person that did - if ot was you, leave a comment! UPDATE: Apparently it's Adam Kinney's from the GotDotNet Workspace
private void BindRssControls(ItemFeedStruct theFeed)
{
string thisUrl = "http://" + Request.Url.Host + Application["AppPath"];
RSSFeed rFeed = new RSSFeed("Latest " + cts.ContentTypeName,thisUrl,"Feed for Communities");
for(int i=0; i < theFeed.items.Length; i++)
{
RSSItem rItem;
if(_contentType != ctl.ForumThreads)
{
rItem = new RSSItem(Server.HtmlEncode(theFeed.items[i].ItemTitle),Server.HtmlEncode(theFeed.items[i].ShortDescription));
}
else
{
string longDesc= theFeed.items[i].LongDescription;
if(longDesc.IndexOf(' ') > -1)
{
longDesc= longDesc.Substring(0,longDesc.LastIndexOf(' '));
}
rItem = new RSSItem(Server.HtmlEncode(theFeed.items[i].ItemTitle),Server.HtmlEncode(longDesc));
}
rItem.PubDate = theFeed.items[i].ItemValidFrom.ToUniversalTime().ToString("r");
rItem.XsdDate = theFeed.items[i].ItemValidFrom.ToString("s");
rItem.Guid = theFeed.items[i].itemId.ToString();
rItem.Link = Server.HtmlEncode(theFeed.items[i].ViewUrl);
rItem.Author = Server.HtmlEncode(theFeed.items[i].AuthorName);
RSSCategoryCollection rCat = new RSSCategoryCollection();
rCat.Add(new RSSCategory(Server.HtmlEncode(theFeed.items[i].Category)));
rItem.Categories = rCat;
rFeed.Items.Add(rItem);
}
Response.ContentType = "text/xml";
Page.EnableViewState = false;
RssLiteral.Text = rFeed.ToString();
}
© 2025 Scott Galloway — Unlicense — All content and source code on this site is free to use, copy, modify, and sell.