Writing RssHandler base on sql database...c#

 Rate It (0)

  • Tags:   
  • RSS

<%@ WebHandler Language="C#" Class="RssHandler" %>

using System;
using System.Web;
using System.Data.Common;
using System.Configuration;
using System.Data;
using System.Xml;


public class RssHandler : IHttpHandler
{
    
 
 
    bool IHttpHandler.IsReusable
    {
        get {return false;}
    }

    DbDataReader GetDataReader()
    {
        ConnectionStringSettings cssettings =
            ConfigurationManager.ConnectionStrings["nardidbConnectionString"];
        DbProviderFactory provider =
            DbProviderFactories.GetFactory(cssettings.ProviderName);
        DbConnection konekcija = provider.CreateConnection();
        konekcija.ConnectionString = cssettings.ConnectionString;
        DbCommand komanda = provider.CreateCommand();
        komanda.Connection = konekcija;
        komanda.CommandText = "Select * From chlanci";
        konekcija.Open();
        return komanda.ExecuteReader(CommandBehavior.CloseConnection);
    }
    void IHttpHandler.ProcessRequest(HttpContext context)
    {
        DbDataReader reader = GetDataReader();
        XmlWriterSettings settings = new XmlWriterSettings();
        settings.Indent = true;
        context.Response.ContentType = "text/xml";
        using (XmlWriter writer = XmlWriter.Create(context.Response.OutputStream, settings))
        {
            writer.WriteStartDocument();
            writer.WriteStartElement("rss");
            writer.WriteAttributeString("version", "2.0");
            writer.WriteStartElement("channel");
            writer.WriteElementString("title", "Nove vijesti od Nardi Hrvatska");
            writer.WriteElementString("link", "http://www.nardi.com.hr");
            writer.WriteElementString("description", "Lista novih članaka");

            while (reader.Read())
            {
                writer.WriteStartElement("item");
                writer.WriteElementString("title", (string)reader["kratko"]);
                writer.WriteElementString("description", (string)reader["tekst"]);
                writer.WriteElementString("link", "http://localhost:8780/web/Default.aspx");
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
            writer.WriteEndElement();
     
        }
    }

        


Above code retrive RSS data from SQL data store.   
               
}

Revision number 1, Wednesday, September 23, 2009 7:40:57 PM by beast_b9
This is not the most up to date version of this article. The most recent version can be found here.

Comments

Related Articles

DataSource Controls

FromScottGu:Scott Mitchell is also writing some great data articles on using the ASP.NET 2.0 DataSource controls for the excellent www.4GuysFromRolla.com ASP.NET site. If you don't visitwww.4GuysFromRolla.com, I highly recommend checking it out (it has

Visual Studio 2008

Visual Studio 2008is theversion of Visual Studio which comes with the .NET Framework 3.5. It was released to MSDN subscribers on 19 November 2007 alongside the.NET Framework 3.5. Visual Studio 2008 can target developmentin .NET Framework versions 2.0, 3.0

Silverlight Examples

Here's some particularly amazing Silverlight examples found in the blogosphere. Also, be sure to check out the Silverlight Galleries and the Learn page. Examples The Silverlight Showcase- Check out this collection of sites and demos on silverlight.net

Shortcuts

Table of Contents

Top Wiki Contributors

(last 30 days)

  1. mbanavige (7)
  2. yrb.yogi (5)
  3. srinivaskotra (3)
  4. XIII (2)
  5. rdmartin33 (2)
  6. Babunareshnarra (2)
  7. Dungimon (1)
  8. ali62b (1)
Microsoft Communities