/** * C# RSS Feed Generator * By Adam Burmister, http://www.flog.co.nz, adam@flog.co.nz * * Use freely, I don't care. */ /// /// Render a series of items as an RSS feed /// public class feed : System.Web.UI.Page { /** Struct for RSS Feed Items - currently targeted towards LanProwler client files, * so customise as required */ public struct FeedItem { public string Title; public string URL; public string Description; public DateTime ModifiedDate; public FeedItem(string Title, string URL, DateTime ModifiedDate, string Description) { this.Title = Title; this.URL = URL; this.ModifiedDate = ModifiedDate; this.Description = Description; } }; /* Constants */ private const int MAX_ITEMS = 50; private const string BASE_URL = "http://adam:90/"; /* Variables */ private XmlTextWriter xwRSS = null; /* XML writer - used for writing RSS feed */ /* Load file list, start render of RSS feed */ private void Page_Load(object sender, System.EventArgs e) { /** In this section of the code you load in your FeedItems array * So for example’s sake: */ FeedItem [] items = new FeedItem[2]; items[0] = new FeedItem("Flog", "http://www.flog.co.nz/", DateTime.Now, "My web site"); items[1] = new FeedItem("For The Masses", "http://www.forthemasses.net/", DateTime.Now, "New Zealand design community news"); RenderFeed("Example RSS Feed", BASE_URL, desc, items); } public void RenderFeed(string ChannelTitle, string ChannelURL, string ChannelDescription, FeedItem [] items) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "text/xml"; xwRSS = new XmlTextWriter(HttpContext.Current.Response.OutputStream, Encoding.UTF8); xwRSS.WriteStartDocument(); xwRSS.WriteStartElement("RSS"); xwRSS.WriteAttributeString("version","2.0"); xwRSS.WriteStartElement("channel"); xwRSS.WriteElementString("title", ChannelTitle); xwRSS.WriteElementString("link",ChannelURL); xwRSS.WriteElementString("description",ChannelDescription); xwRSS.WriteElementString("ttl","30"); /* add any other RSS valid entries here */ //xwRSS.WriteElementString("copyright","© 2000 - 2006 SomeCompany"); for(int i=0; i