Thursday, 4 April 2013

how to Create RSS feed Using Asp.net | RSS Feed Sample using asp.net

Press Me 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Text;
using DatabaseModel;
public partial class Default2 : System.Web.UI.Page
{
    DatabaseEntities1 o = new DatabaseEntities1();
    protected void Page_Load(object sender, EventArgs e)
    {

        Response.Clear();
        Response.ContentType = "text/xml";
        XmlTextWriter TextWriter = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
        TextWriter.WriteStartDocument();
        //Below tags are mandatory rss
        TextWriter.WriteStartElement("rss");
        TextWriter.WriteAttributeString("version", "2.0");
        // Channel tag will contain RSS feed details
        TextWriter.WriteStartElement("channel");
        TextWriter.WriteElementString("title", "C#.NET,ASP.NET Samples and Tutorials");
        TextWriter.WriteElementString("link", "http://chinmayaparija.blogspot.in");
        TextWriter.WriteElementString("description", "Free ASP.NET articles,C#.NET,ASP.NET tutorials and Examples,Ajax,SQL Server,Javascript,XML,GridView Articles and code examples -- by chinmaya parija");
        TextWriter.WriteElementString("copyright", "Copyright 2009 - 2010 dotnetpoint chinmayaparija.blogspot.in. All rights reserved.");
        var m=(from x in o.GTHs select x).ToList();
        for(int i=0;i<m.Count;i++)
        {
            TextWriter.WriteStartElement("item");
            TextWriter.WriteElementString("title",m[i].Title.ToString());
            TextWriter.WriteElementString("description", m[i].Description.ToString());
            TextWriter.WriteElementString("link",m[i].Url.ToString());
            TextWriter.WriteEndElement();
        }
        TextWriter.WriteEndElement();
        TextWriter.WriteEndElement();
        TextWriter.WriteEndDocument();
        TextWriter.Flush();
        TextWriter.Close();
        Response.End();
    }
}


No comments:

Post a Comment