|
using System;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml;
using System.Text;
public partial class RSSWrite : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnPublish_Click(object sender, EventArgs e)
{
Response.Clear();
XmlTextWriter RSSFeed = new XmlTextWriter(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "AvgPriceList.xml",Encoding.UTF8);
// Write the rss tags like title, version, Channel, title, link description copyright etc.
RSSFeed.WriteStartDocument();
RSSFeed.WriteStartElement("rss");
RSSFeed.WriteAttributeString("version", "2.0");
RSSFeed.WriteStartElement("channel");
RSSFeed.WriteElementString("title", "Products Above Average Prices");
RSSFeed.WriteElementString("link", "http://localhost/RSSFeeds");
RSSFeed.WriteElementString("description", "Details of all the Products Average Prices");
RSSFeed.WriteElementString("copyright", "Copyright Indrajeeth 2010");
//here I am binding grid using SQLdatasource, This is for the example purpose reading from gridview
//it is not recomended use gridview, datatables,dataset to write data
// Loop through the Gridview of the database and add them to the RSS feed
foreach (GridViewRow grvRow in grvRSS.Rows)
{
RSSFeed.WriteStartElement("item");
RSSFeed.WriteElementString("ProductName", grvRow.Cells[0].Text);
RSSFeed.WriteElementString("UnitPrice", grvRow.Cells[1].Text);
RSSFeed.WriteElementString("Link", "http://localhost/RSSFeeds/ProductList.xml");
RSSFeed.WriteElementString("PublishDate", DateTime.Now.ToString());
RSSFeed.WriteEndElement();
}
RSSFeed.WriteEndElement();
RSSFeed.WriteEndElement();
RSSFeed.WriteEndDocument();
RSSFeed.Flush();
RSSFeed.Close();
Response.Write("RSS Feed is created. For reading Rss feed <a href='RSSRead.aspx'>Click here.</a>");
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Am Indrajeet T. Sutar. I am a web developer. I am working on .net technology. I have completed my Masters in Computers and Management (people call it as MCA, MBA etc.) Apart from programming i do photography (not regularly though), traveling and reading books.