Created
January 16, 2011 12:55
-
-
Save ekampf/781762 to your computer and use it in GitHub Desktop.
ASp.NET MVC action result that renders an RSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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