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.

  Home  |   Contact  |   Syndication    |   Login
  82 Posts | 1 Stories | 40 Comments | 7 Trackbacks

News




Google RankGoogle PR™ - Post your Page Rank with MyGooglePageRank.com



The content on this site represents my own personal opinions and thoughts at the time of posting, and does not reflect those of my employer's in any way.

Disclaimer:- All postings in this blog is provided "AS IS" with no warranties, and confers no rights.

Archives

Post Categories

Image Galleries

Atlas

Error

OutLook

SharePointService

Usefull Site Links

public

{

void CreateXML()

string strselect = "Your Query here";

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

 

try

        {

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

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

            writer.WriteStartDocument();

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

            writer.WriteStartElement("rss");

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

            writer.WriteStartElement("channel");

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

            writer.WriteElementString("link", "http://yoursite.com");

            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 = "http://www.yoursite.com/index.aspx?Id=" + listid;

 

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

                writer.WriteStartElement("item");

                writer.WriteElementString("title", strTopic);

                writer.WriteElementString("link", strlink);

                writer.WriteElementString("description", strArticle);

                writer.WriteElementString("guid", strlink);

                writer.WriteEndElement();

            }

 

            writer.WriteEndDocument();

            writer.Flush();

            writer.Close();

        }

        catch (Exception e)

        {

            throw e;

        }

}

posted on Tuesday, March 06, 2007 7:22 AM

Feedback

# re: Creating RSS feed + C# 5/4/2009 7:09 AM D Waterfield
Nicely done.
Concise and to the point.

# re: Creating RSS feed + C# 6/17/2009 4:49 AM redguna

Hi nice code but i want to update the xml ?

visit rednews.in/blog.aspx?id=rssfed

# re: Creating RSS feed + C# 11/9/2009 1:17 AM martin
nice one

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: