Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

RSS Enabling a website

Posted on 2009-04-07
1
Medium Priority
?
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 14

Accepted Solution

by:
GiftsonDJohn earned 1000 total points
ID: 24089161
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

636 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