July 23, 2009
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
using System.Text;
using System.ServiceModel.Syndication;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class RSS : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "text/xml";
XmlTextWriter rssFeed = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
rssFeed.WriteStartDocument();
rssFeed.WriteStartElement("rss");
rssFeed.WriteAttributeString("version", "2.0");
rssFeed.WriteStartElement("channel");
rssFeed.WriteElementString("title", "University News");
rssFeed.WriteElementString("link", HttpContext.Current.Request.Path);
//a file with ".rss" extension, in root directory, is required to recognize the request as a feed
rssFeed.WriteElementString("link", "http://www.google.com/feed.rss");
rssFeed.WriteElementString("description", "The latest university news and information.");
rssFeed.WriteElementString("copyright", "Copyright 2009 techelp.in. All rights reserved.");
SqlConnection SqlCon;
SqlCommand SqlCom;
SqlDataReader SqlDR;
SqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCom = new SqlCommand("select * from dbo.tblUniversityList", SqlCon);
SqlCom.CommandType = CommandType.Text;
if (SqlCon.State == ConnectionState.Closed)
{
SqlCon.Open();
}
SqlDR = SqlCom.ExecuteReader();
while (SqlDR.Read())
{
rssFeed.WriteStartElement("item");
string Name = SqlDR["University"].ToString();
rssFeed.WriteElementString("title", Name);
rssFeed.WriteElementString("description", SqlDR["University"].ToString());
rssFeed.WriteElementString("link", HttpContext.Current.Request.Path + SqlDR["ID"]);
rssFeed.WriteEndElement();
}
SqlDR.Close();
SqlCon.Close();
rssFeed.WriteEndElement();
rssFeed.WriteEndElement();
rssFeed.WriteEndDocument();
rssFeed.Flush();
rssFeed.Close();
Response.End();
}
}
I cannot believe this is true!
[Reply]
Link | August 5th, 2009 at 11:08 PM
Hey, ok, I get it, I guess – but does this really work?
[Reply]
Link | August 12th, 2009 at 12:37 AM