Register
|
Articles
|
Questions
|
Projects
|
Asp.Net Tips
|
Asp.Net News
|
Tutorials
|
Search
Login
Articles
Asp.Net 2.0
AJAX
ADO.Net
C#
Javascript
Books
Asp.Net 2.0
AJAX
ADO.NET
C#
JavaScript
MS SQL Server
VB.NET
XML
Web Service
Resources
Downloads
Free Tech Magazines
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Sample source code for Rss Feeds creation and Display in browser friendly design
We have provided below sample source code for creating RSS feeds in Asp.Net and to display it in browser friendly designs and layouts using XSLT. You can copy and paste it in your pages to create the sample application.
Code for XSLT file (rss.xsl)
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <head> <title> <xsl:value-of select="/rss/channel/title" /> </title> </head> <body> <table width="75%" border="1" cellspacing="1" cellpadding="1"> <tr> <td bgcolor="#cccccc"> <xsl:value-of select="/rss/channel/title" /> </td> </tr> </table> <table width="75%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="15"></td> </tr> <tr> <td > This page is the sample syndication feed. </td> </tr> <tr> <td height="15"></td> </tr> <tr> <td>You can provide some Description about the RSS Feeds </td> </tr> </table> <table width="75%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="15"></td> </tr> <xsl:for-each select="/rss/channel/item"> <tr> <td> <a href="{link}"> <xsl:value-of select="title" /> </a> </td> </tr> <tr> <td height="5"> <xsl:value-of select="description" /> </td> </tr> <tr> <td height="10"> </td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Source Code for aspx.cs file (rss.aspx.cs)
using System.Text; using System.Xml; using System.Data.SqlClient; protected void Page_Load(object sender, EventArgs e) { Response.Clear(); Response.ContentType = "text/xml"; XmlTextWriter xtw = new XmlTextWriter(Response.OutputStream, Encoding.UTF8); xtw.WriteStartDocument(); string processtext = "type=\"text/xsl\" href=\"rss.xsl\""; xtw.WriteProcessingInstruction("xml-stylesheet", processtext); xtw.WriteStartElement("rss"); xtw.WriteAttributeString("version", "2.0"); xtw.WriteStartElement("channel"); xtw.WriteElementString("title", "Latest Articles List"); xtw.WriteElementString("link", "http://www.yourwebsite.com/"); xtw.WriteElementString("description", "some description here"); string sql = "Select * from Articles Order by Created_Date Desc"; SqlDataAdapter da = new SqlDataAdapter(sql, "Your connection string"); DataTable dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { xtw.WriteStartElement("item"); xtw.WriteElementString("title", dt.Rows[i]["Art_Title"].ToString()); xtw.WriteElementString("description", dt.Rows[i]["Art_Subject"].ToString()); xtw.WriteElementString("link", "http://www.yourwebsite.com/"+dt.Rows[i]["Art_Url"].ToString()); xtw.WriteElementString("pubDate",XmlConvert.ToString(Convert.ToDateTime(dt.Rows[i]["L_Update"].ToString()))); xtw.WriteEndElement(); } } xtw.WriteEndElement(); xtw.WriteEndElement(); xtw.WriteEndDocument(); xtw.Flush(); xtw.Close(); }
Back to Article
Advertisements
Home
About us
Contact Us
Links
Advertise
Privacy Policy
Copyright ©
2008
. www.AspdotnetCodes.com. All rights reserved.