I haven’t used any built in application or framework to development a custom web site. All the code has been written from scratch by me. It is not a big site, but I keep on adding things as they are needed. I don’t know any tool which could automatically generate RSS feed from your won data, so I decided to write my own code.
Here is the code which will generate RSS feed for most recent post in this web site.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
protected void Page_Load(object sender, EventArgs e) { // Clear any previous output from the buffer Response.Clear(); Response.ContentType = "text/xml"; XmlTextWriter feedWriter = new XmlTextWriter(Response.OutputStream, Encoding.UTF8); feedWriter.WriteStartDocument(); // These are RSS Tags feedWriter.WriteStartElement("rss"); feedWriter.WriteAttributeString("version", "2.0"); feedWriter.WriteStartElement("channel"); feedWriter.WriteElementString("title", "Sample Code"); feedWriter.WriteElementString("link", "http://www.samplesite.com"); feedWriter.WriteElementString("description", "Sample Coding"); feedWriter.WriteElementString("copyright", "Copyright 2008 samplesite.com. All rights reserved."); // Get list of 20 most recent posts PostList posts = PostList.GetTopPostList(AppGlobals.MainArgs, 20); // Write all Posts in the rss feed foreach(PostInfo post in posts) { feedWriter.WriteStartElement("item"); feedWriter.WriteElementString("title", post.Title); feedWriter.WriteElementString("description", post.PostHtml); feedWriter.WriteElementString("link", UrlHelper.GetShowPostUrl(this, post.Name)); feedWriter.WriteElementString("pubDate", post.DatePosted.ToString()); feedWriter.WriteEndElement(); } // Close all open tags tags feedWriter.WriteEndElement(); feedWriter.WriteEndElement(); feedWriter.WriteEndDocument(); feedWriter.Flush(); feedWriter.Close(); Response.End(); } |