Saturday 26 September 2015

how to Create RSS feed Using Asp.net using C#


create RSS fied



Description:-

In this example we explain that how to create RSS fied or create sample of the RSS fied in asp.net using C#.


First of all what is RSS. Its stands for “Realy Simple Syndication”. RSS are generally used to solve problems for users that regularly uses the internet’s provide user to easily stay informed by retrieving the content from the websites or any blogs in which you are interested. User can save the time by using RSS facility you do not need to visit each website individually.




RSSFied.aspx:-

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RSSFied.aspx.cs" Inherits="RSSFied" %>
<%@ OutputCache Duration="120" VaryByParam="*" %>



RSSFied.aspx.cs:-

using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
public partial class RSSFied : System.Web.UI.Page
{
  
        protected void Page_Load(object sender, EventArgs e)
        {
          
            DataTable dt = new DataTable();
            dt.Columns.Add("Title");
            dt.Columns.Add("Description");
            dt.Columns.Add("URL");
            DataRow dr = dt.NewRow();
            dr[0] = "AspSolutionKirit";
            dr[1] = "this blog totaly provide Asp Dot program and mvc program for professional developer.";
            dr[2] = "http://aspsolutionkirit.blogspot.in/";
            dt.Rows.Add(dr);
            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 and MVC Programs and Tutorials");
            TextWriter.WriteElementString("link", "http://aspsolutionkirit.blogspot.in/");
            TextWriter.WriteElementString("description", "fully ASP.NET control articles,C#.NET,Linq,Ajax,SQL Server,Javascript,Jquery,CSS,XML,GridView Articles,MVC");
            TextWriter.WriteElementString("copyright", "Copyright 2013 - 2014 aspsolutionkirit.blogspot.in. All rights reserved.");
            foreach (DataRow oFeedItem in dt.Rows)
            {
                TextWriter.WriteStartElement("item");
                TextWriter.WriteElementString("title", oFeedItem["Title"].ToString());
                TextWriter.WriteElementString("description", oFeedItem["Description"].ToString());
                TextWriter.WriteElementString("link", oFeedItem["URL"].ToString());
                TextWriter.WriteEndElement();
            }
            TextWriter.WriteEndElement();
            TextWriter.WriteEndElement();
            TextWriter.WriteEndDocument();
            TextWriter.Flush();
            TextWriter.Close();
            Response.End();
        }
    }


0 comments:

Post a Comment