Geeks With Blogs
Gaurav Taneja Great dreams... never even get out of the box. It takes an uncommon amount of guts to put your dreams on the line, to hold them up and say, "How good or how bad am I?" That's where courage comes in.



void CreateXML()

string strselect = "Your Query here";

        DataSet ds = ObjectName.ExecuteQuery(strselect, "Table Name");




            string path = HttpContext.Current.Server.MapPath("rss.xml");

            XmlTextWriter writer = new XmlTextWriter(path, Encoding.UTF8);


            writer.WriteProcessingInstruction("xml-stylesheet", "type='text/xsl' href='lead.xsl'");


            writer.WriteAttributeString("version", "2.0");


            writer.WriteElementString("title", "Your Feed Title");

            writer.WriteElementString("link", "");

            writer.WriteElementString("description", "Your description");

            writer.WriteElementString("language", "en-us");

            string GMTDate = System.TimeZone.CurrentTimeZone.ToUniversalTime(DateTime.Now).ToString("r");

            writer.WriteElementString("lastBuildDate", "<br>" +  GMTDate);


            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)


                string strTopic = ds.Tables[0].Rows[i]["Topic"].ToString();

                string strArticle = ds.Tables[0].Rows[i]["Article"].ToString();

                string strlink = "";

                string PostDate = ds.Tables[0].Rows[i]["PostDate"].ToString();

                string listid = ds.Tables[0].Rows[i]["Id"].ToString(); ;

                strlink = "" + listid;


                strlink = strlink.Replace("\n", "");


                writer.WriteElementString("title", strTopic);

                writer.WriteElementString("link", strlink);

                writer.WriteElementString("description", strArticle);

                writer.WriteElementString("guid", strlink);








        catch (Exception e)


            throw e;



Posted on Tuesday, March 6, 2007 7:22 AM .Net | Back to top

Comments on this post: Creating RSS feed + C#

# re: Creating RSS feed + C#
Requesting Gravatar...
Nicely done.
Concise and to the point.
Left by D Waterfield on May 04, 2009 7:09 AM

# re: Creating RSS feed + C#
Requesting Gravatar...

Hi nice code but i want to update the xml ?

Left by redguna on Jun 17, 2009 4:49 AM

# re: Creating RSS feed + C#
Requesting Gravatar...
nice one
Left by martin on Nov 09, 2009 1:17 AM

Your comment:
 (will show your gravatar)

Copyright © Gaurav Taneja | Powered by: