Solved

RSS Enabling a website

Posted on 2009-04-07
1
300 Views
Last Modified: 2012-05-06
Experts i have my web site written using ASP.NET,C # and now i have a requirement to RSS enable so other vendors can read news off our website and make it RSS feed read capable ( i am not sure if that is the right language) . How an i do that ? How much time it may take to enable a website of about 10 web forms and about 10MB of data ?
0
Comment
Question by:dotnetpro
1 Comment
 
LVL 14

Accepted Solution

by:
GiftsonDJohn earned 250 total points
Comment Utility
Hi There,

You can enable RSS syndication by writing a small piece of code. Create Feed.aspx and use the following code snippet for generating RSS feeds.

Then you have to include the following tag in your page to enable syndication.

<link rel="alternate" type="application/rss+xml" title="Test RSS Feeds" href="http://www.site.com/Feed.aspx" />

Here you go.


        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", "RSS Feed for Site");

        objX.WriteElementString("link", "http://www.site.com/TargetPage.aspx");

        objX.WriteElementString("description", "Just a sample RSS Feeds");

        objX.WriteElementString("copyright", "(c) 2009 Copyright information");

        objX.WriteElementString("ttl", "720");       
 

        SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);

        sqlCon.Open();
 

        string sql = "select top 50 NewsID, Title, url, pubDate, photourl[photo], details  from tblNews";

        SqlCommand sqlCmd = new SqlCommand(sql, sqlCon);

        SqlDataReader sqlRdr = sqlCmd.ExecuteReader();

        if (sqlRdr.HasRows)

        {

            while (sqlRdr.Read())

            {

                objX.WriteStartElement("item");

                objX.WriteStartElement("title");

                objX.WriteCData(sqlRdr["Title"].ToString());

                objX.WriteEndElement();
 

                objX.WriteStartElement("description");

                objX.WriteCData("<table><tr><td rowspan=\"2\"><img src=\"" + sqlRdr.GetString("Photo") + "\" alt=\"" + sqlRdr["Title"].ToString() + "\" width=\"40\" height=\"50\" /><td>" + sqlRdr["Details"].ToString() + "</td></tr><tr><td>Published Date : " + sqlRdr.GetDateTime(3).ToString("dd MMM yyyy") + "</td><td></td></tr><tr><td colspan=\"3\">&nbsp;</td></tr></table>");

                objX.WriteEndElement();
 

                objX.WriteStartElement("link");

                objX.WriteCData(sqlRdr["url"]);

                objX.WriteEndElement();
 

                objX.WriteElementString("pubDate", sqlRdr.GetDateTime(3).ToString("R"));
 

                objX.WriteEndElement();

            }

        }        

        sqlRdr.Close();

        sqlCon.Close();
 

        objX.WriteEndElement();

        objX.WriteEndElement();

        objX.WriteEndDocument();

        objX.Flush();

        objX.Close();

        Response.End();

Open in new window

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Where to begin studying? 5 63
c# code 19 56
Trouble with References... 5 21
fomat Json objects 6 15
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now