Skip to content

Instantly share code, notes, and snippets.

@ekampf
Created January 16, 2011 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekampf/781762 to your computer and use it in GitHub Desktop.
Save ekampf/781762 to your computer and use it in GitHub Desktop.
ASp.NET MVC action result that renders an RSS
public class RssResult : FileResult
{
private readonly SyndicationFeed _feed;
/// <summary>
/// Creates a new instance of RssResult
/// </summary>
/// <param name="feed">The feed to return the user.</param>
public RssResult(SyndicationFeed feed)
: base("application/rss+xml")
{
_feed = feed;
}
/// <summary>
/// Creates a new instance of RssResult
/// </summary>
/// <param name="title">The title for the feed.</param>
/// <param name="feedItems">The items of the feed.</param>
public RssResult(string title, List<SyndicationItem> feedItems)
: base("application/rss+xml")
{
_feed = new SyndicationFeed(title, title, HttpContext.Current.Request.Url) {Items = feedItems};
}
protected override void WriteFile(HttpResponseBase response)
{
using (XmlWriter writer = XmlWriter.Create(response.OutputStream))
{
_feed.GetRss20Formatter().WriteTo(writer);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment