Tips Station Asp.net Article Seo Articles
Tutorials Code Samples
›  Home
›  Mission
›  About us
›  Contact Us
›  Feedback
›  Terms & Condition
Asp Articles
IT Solutions
 
› ASP.NET

› Programming Tips

› Ajax

› Asp

› ADO.NET

› Databases

› SEO

› CSS And Designing

› Php

 
Most Viewed Articles
 
› Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

› Change theme dynamically without page refresh in ASP.NET

› Install AJAX On Machines Running Visual Studio 2005

› Creating Pretty Popups Using AJAX

› Simple ASP Image Resize Function

› SQL Server Performance Counters

› ASP.Net Interview Questions And Their Answers

› Encode Url using ASP

› Difference Between DataGrid and GridView in Asp.Net

› Select Specific Value WithIn Drop Down List Or Radio Button List

more...
 
 
Home> ASP.NET
 
Create an RSS Feed in Asp.net
 
Add an RSS Feed to your site
RSS feeds can be a useful way of letting your visitors see new content from your site.

To create this on your site, add a new page entitled "rssfeed.aspx" and add this to the Page Load event:
  1. ' Declarations    
  2. Dim dtList As New DataTable  
  3. Dim intCount As Integer = 10 ' Number of records to show  
  4.   
  5. ' Set the content attributes  
  6. Response.ContentType = "text/xml"  
  7. Response.ContentEncoding = Encoding.UTF8  
  8.   
  9. ' Use an XmlTextWriter to write the XML data to a string...  
  10. Dim sw As New StringWriter  
  11. Dim writer As New XmlTextWriter(sw)  
  12.   
  13. ' write out the rss and version  
  14. writer.WriteStartElement("rss")  
  15. writer.WriteAttributeString("version", "2.0")  
  16.   
  17. ' write out <channel>  
  18. writer.WriteStartElement("channel")  
  19.   
  20. ' write out <channel>-level elements  
  21. writer.WriteElementString("title", "ASP.NET Library - Articles")  
  22. writer.WriteElementString("link", "http://aspnetlibrary.com")  
  23. writer.WriteElementString("description", "A list of articles from the ASP.NET Library")  
  24. writer.WriteElementString("ttl", "60")  
  25.   
  26. ' Insert your code here to get the data  
  27. dtList = ...  
  28.   
  29. ' write out an <item> element for each result  
  30. For i As Integer = 0 To (intCount - 1)  
  31.   
  32.     ' write out the start <item> element  
  33.     writer.WriteStartElement("item")  
  34.   
  35.     writer.WriteElementString("title", dtList.Rows(i).Item("MyTitleField").ToString)  
  36.     writer.WriteElementString("link", "http://aspnetlibrary.com/articledetails.aspx?articleid=" & dtList.Rows(i).Item("MyIDField").ToString)  
  37.     writer.WriteElementString("description", dtList.Rows(i).Item("MyDescriptionField").ToString)  
  38.     writer.WriteElementString("author", "Mark Smith")  
  39.     writer.WriteElementString("posted", dtList.Rows(i).Item("MyCreatedOnField").ToString)  
  40.   
  41.     ' write out closing </item> element  
  42.     writer.WriteEndElement()  
  43.   
  44. Next  
  45.   
  46. ' write out closing </channel> element  
  47. writer.WriteEndElement()  
  48.   
  49. ' write out closing </rss> element  
  50. writer.WriteEndElement()  
  51.   
  52. ' close the writer  
  53. writer.Close()  
  54.   
  55. ' write out the xml directives and the rss feed string  
  56. Response.Write("<?xml version=""1.0"" encoding=""ISO-8859-1""?>")  
  57. ' You can also specify an xsl sheet if needed  
  58. ' Response.Write("<?xml-stylesheet type=""text/xsl"" href=""~/stylesheets/rssTemplate.xsl""?>")  
  59. Response.Write(sw.ToString())  
  60.   
  61. ' Clean Up  
  62. writer = Nothing  
  63. sw = Nothing  

As I mentioned above, you can see this in action here so to get a working example on your site, you'll need to:
 
  1. Add the code that you use to connect to your database (in the section with the comment "Insert your code here to get the data").
  2. Customise the sections where I have referenced my site and set the database fields in the "item element" loop.
  3. Make sure you import the System.IO, System.Xml and System.Data classes.
 
 
 
Vrp Technologies
 
Serversea Hosting
 
 
Latest Articles
 
› Sending SMS With PHP

› MySQL Join Tutorial

› Make An RSS Feed Using PHP

› Intro To Object: Option Variables

› Design An Online Chat Room With PHP And MySQL

› Create Tell A Friend Script With HTML & PHP

› Benchmark And Optimize PHP Script Speed

› What Kind of DBA Are You?

› SQL Server Performance Counters

› SQL Server Performance Tips

more...
 
Random Articles
 
› Search Engine Optimization & Submission Strategies - A Beginners Guide

› Change theme dynamically without page refresh in ASP.NET

› Create Tell A Friend Script With HTML & PHP

› How to connect to a database via a DSN-Less connection - ASP

› Displaying an RSS Feed using ASP

› Access Master Page controls from the Content Page - Asp.net

› How to export a GridView to Excel - Asp.net

› Top 10 Best Practices for Production ASP.NET Applications

› Clear all TextBox values in Asp.Net

› How to Start with ASP.NET AJAX

more...
 
Home Mission About us Contact us Feedback Terms Conditions
2008 © Copyright TipsStation. All rights reserved.