.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> File Operation >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Sample RSS in ASP.NEt

Posted By:Athira Sreejith       Posted Date: March 25, 2009    Points: 10    Category: File Operation    URL: http://www.dotnetspark.com  
 

Code to create RSS feeds in asp.net using C# dynamically

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Text;
using System.Data.SqlClient;
public partial class sampleRSS : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();
        Response.ContentType = "text/xml";
        XmlTextWriter objx=new XmlTextWriter(Response.OutputStream,Encoding.UTF8);
        objx.WriteStartDocument();
        objx.WriteStartElement("rss");
        objx.WriteAttributeString("Version","2.0");
        objx.WriteStartElement("channel");
        objx.WriteElementString("title","ASP.NET NewsWire");
        objx.WriteElementString("link","http://www.uberasp.net/newswire.aspx");
        objx.WriteElementString("description","The latest headlines and articles from the world of  ASP.NET,Microsoft's Web Development Platform");
        objx.WriteElementString("copyright","All rights Reserved");
        objx.WriteElementString("tt1","5");
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
        con.Open();
        string qry = "select top 10 BookTitle,BookPrice from ShopCart";
        SqlCommand cmd = new SqlCommand(qry, con);
        SqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            objx.WriteStartElement("item");
            objx.WriteElementString("title",dr.GetString(0));
            objx.WriteElementString("description",dr.GetValue(1).ToString());
            objx.WriteEndElement();
        }
        dr.Close();
        con.Close();
        objx.WriteEndElement();      
        objx.WriteEndElement();
        objx.Flush();
        objx.Close();
        Response.End();
        }

    }

 


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend