A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
Create an RSS feed using ASP.NET 2.0This tutorial will show you how to create a dynamic XML RSS 2.0 feed using ASP.NET 2.0 (C#). The headlines will be retrieved from a SQL database. |
On Wednesday, January 4th 2006 at 09:58 AM By Andrew Pociu (View Profile) ![]() ![]() ![]() ![]() (Rated 4.6 with 74 votes) |
||||
|
I don't think there's a need for explaining what RSS is, or what RSS does. Most of the time, the headlines of an RSS feed are retrieved from a database, such as SQL server. An example of this is Feedpedia.com which creates feeds containing the latest headlines retrieved from the website's database. One of these feeds is located at http://www.feedpedia.com/RSS/TodaysHeadlines.aspx?Group=13. In this tutorial we're going to create a similar RSS feed, using ASP.NET 2.0. In the ASP.NET 2.0 project, create a new file which will be the RSS feed. We used "TodaysHeadlines.aspx". Now open the markup of the file and replace everything inside it with the following two lines: Don't forget to change the CodeFile and Inherits attributes of the Page tag in case you gave your RSS file a different name than TodaysHeadlines.aspx. If you're wondering what the second page does: it tells the ASP.NET server to keep the page in cache for 120 seconds (2 minutes) so that the SQL server doesn't have to be accessed every time someone opens your RSS feed. You can change the duration depending on how often your content updates.
Now since we are already discussing the OutputCache, I want to bring your attention towards something. If you're going to create a dynamic RSS feed file to which you're going to pass a parameter which changes the content of the feed (such as the one on Feedpedia: http://www.feedpedia.com/RSS/TodaysHeadlines.aspx?Group=13), the cache you will create you some problems: when you open the RSS feed with a different attribute (in Feedpedia's case, a different Group ID), the content will not change, but the cached one will be shown. In that case you will need to tell the cache that the content varies by that parameter, and it should build a different cache based on the parameter passed. Here's how you can do that:
Now if you didn't understand any of my mumbling above, don't worry, as long as you don't plan to pass parameters to the RSS feed, everything will work fine for you without the VaryByParam attribute. Believe it or not, we're done with the markup, so switch to code view. Add the following using statements at the top:
Now what's left to do for your RSS feed to work, is add this code in the Page_Load event:
Of course, you'll need to do the necessary changes so that the code matches your SQL database table. If you have any questions or doubts about the code, don't hesitate to place a comment for this tutorial. I will answer ASAP. If you did everything right, your RSS feed will be valid and should have a structure similar to the one below: ![]() There are several tags which you can add to the RSS feed, such as the author of the headline, the category or an unique ID. You can find more information about this at the RSS 2.0 specification page. |
|||||
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
|||||
|
|||||
Current CommentsExcellent informative article.
pubDate is not in the correct format.
E.g. Tue, 10 Jan 2006 08:00:00 GMT
Hi,
A handy tutorial there but i'm new to the asp.net and its working! Could it be a possibility that this tut can have some screenshots and some easier to folllow instructions
sorry to be a pain
I have been looking for something like this for months! Thanks a lot, it looks great!
This is just what I was looking for. Everywhere I went I saw references to the 4Guys solution, which started off OK, but my ISP doesn't all access to system.io, which 4Guys use to stream the feed. Using the XMLTextWriter and streaming directly to the response.outputstream go me around the problem.
Once again many thanks, just a shame is wasn't higher up the search engine order.
Regards,
Jason.
Keep it up. You have a good job..
good this site.ok
to get this to work with IE7 and Outlook 2007, you need to remove the content type of text/xml
Really nice!
How would one use CDATA in the for the item/description element.
I am in the same boat jeff, i am pulling info from the database and using an editor to put the info into the database so when it is returned, i am getting an error. any help with be greatly appreciated
You can try Feedity - http://www.feedity.com to create custom RSS web feeds from non-syndicated webpages.
kbdhuigsdfkvxclvc vki jodf.gdf klfdnmbdfbfdb
kbdhuigsdfkvxclvc vki jodf.gdf klfdnmbdfbfdb
I am new to asp.net. how can I create a feed that will do the above but pull information from a table that has multiple rows with the same id. The table I have has multiple rows with the same id, has a field xpath listing the category of the data then has a field with data I'd like to display that within the category. ex
row 1: id=1, xpath=name, name=jim
row 2: id=1, xpath=location, location=123 street
row 3: id=1, xpath=date, date=2.3.05
So, How can I get the rss feed to display all the records in the table but group the items by id, lable subcategories in the xml tag then insert the data from the category in the brackets.
i am not able to see the xml file but it is showing google reader with my application link.How to get the xml file output?
hi,
thank you very much.
but i have still problem with it.
i want to know that how to use RSS in our site.
what to do in our site.
regards...
ravi
hi,
its a nice article and its all about what i was looking for.
great article , do you have a vb.net code example you can send me
Hi,
For a start I'm using vb.net not c#.
I dont know why, but I am getting errors with the aspx code. The errors are:
Validation (): Element 'html' occurs too few times.
'Context' is not a member of 'top10Feed'
'Context' is not a member of 'top10Feed'
Thats not a typo, the error is appearing twice. The pages are top10Feed.aspx, and obviously top10Feed.aspx.vb
It seems strange as everyone else seems to have just gone straight through with the code without any problems.
Any help would be greatly appreciated.
Hello friend,
This is very interesting and useful topic.
But let me know how can i add style sheet using this xmltextwriter.
Hi,
Useful article.
How can i use RSS reader with respect to RSS feed?
Thanks
Shobha
excellent job thank you
<b>How can i use RSS reader with respect to RSS feed? </b>
Hello shobha,
There are many ways to use rss feed in our application. example using javascript or in .net programming etc...
in .net we have xmltextreader we can use that reader object to read rss feed. we have to past here just rss url of feed.
one more thing you can get rssreader.dll from net you can use that assembly to read rss feed.
you can find it from net.
Thanks
Regards
Rajni Padhiyar
Sr. Software Engineer.
www.Ojeez.com/rajni
Beautiful.
Plz tel me wat is the SP \"GetTodaysHeadlines\"... can u plz give me the procedure
this is excellent article for beginer
Good and Simple article for understanding.
But I want to show the above data generated in a GridView.
I know we can read XML file using the XMLTextReader.
We have to pass the Path of the XMl file to the XMLTextReader Object.
If I give Aspx page instead of the XML.
It is giving me Error.
How Can I show above Data in A Gridview.
Article really helped me out. Thanks a lot.
I google for this today and got another way in asp.net 2.0 here. http://weblogs.asp.net/skillet/archive/2006/08/29/RSS-in-.NET-Made-Easy-with-XML-Serialization.aspx
Hey man thanks for the Nice Article...Can u please tell how can i make RSS Feed for my Blog Entry/Article...& that should be redirect other site....please Guide me if U can....Thanks in advance.
Great... struggled with different tutorials. This was perfect. Worked like a charm.
good article......
but i did not understand VaryByParam="Group"
and i think it is related with my problem .
my prob. is when i update in the database the changes does not reflect on the rss feed????
this is fantastic, saved me a couple hours - thanks!
Jake
It seems to me very convincing
Thanks for information,
But i have one doubt.how to sbscribe news.
please inform me.
I want to search for RSS field, can u help me.
Informative and simple article.
Appreciate your hard work.
Thanks.
DotNetGuts
http://dotnetguts.blogspot.com
Thanks it helped me.
This Test for subscibe me.
Thank
I have tried this tutorial, and everything worked fine, except for one thing.
When I delete a record from the database, it doesn't reflect on the rss feed. The old records are still there. I am pretty sure its to do with the catch.
Can anybody help?
Do you have this tutorial in Visiual Basic version?
currently I'm trying this to be used in the cooliris that i've been making for some while.
Somehow i'm wondering, this rss will appear in the form of rss or xml file? or whn you load the aspx file, the content will be showed in the page itself?
Because cooliris needs a file to load its content...
thanks
THANKS! ;)
I used your article and I developed this app for vb.net. Thanks again it's an excellent starting point for me. However I am struggling to add the code to extend the feed so that is shows images? Can you please post some code that will generate images? this is my last attempt below:
xFeed.WriteStartElement("image")
xFeed.WriteElementString("url", "http://www.roxypalace.com/games/EN/Slots/Crazy_Chameleons.gif")
xFeed.WriteElementString("link", "http://www.roxypalace.com/Winston?RSSImage")
xFeed.WriteEndElement()
I have a problem in RSS Feed that I am creating feed dynamically and when daily news are entered, feed contents are changed. My problem is when I enter "
I need to get the data from an MS Access database. What would the code look like for that? I would think that it would replace the following:
// Objects needed for connecting to the SQL database
SqlConnection SqlCon;
SqlCommand SqlCom;
SqlDataReader SqlDR;
// Edit to match your connection string
SqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
// Edit to match your stored procedure or SQL command
SqlCom = new SqlCommand("GetTodaysHeadlines", SqlCon);
SqlCom.CommandType = CommandType.StoredProcedure;
if (SqlCon.State == ConnectionState.Closed)
{
SqlCon.Open();
}
SqlDR = SqlCom.ExecuteReader();
Thanks for your help.
Here's a way to format your date in vb.net, probably works the same in C# i think:
Format(Date.ToUniversalTime, "R")
thought this would be helpful to someone, cause it was to me B)
I think this is an awesome article.
But, can somebody please tell me how can i display images in the RSS, just like that we fetched other data from database. I have stored images in binary format in database.
This is my visual basic version which have modified slightly to handle tracking etc. Below is my VB code for the feed:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim MyAffTrackerRecieve As String
MyAffTrackerRecieve = Request.QueryString("MyAffTracker")
'Response.Write(MyAffTrackerRecieve)
'RSS Feed creation below
Response.Clear()
Response.ContentType = "text/xml"
Dim xFeed As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
xFeed.WriteStartDocument()
xFeed.WriteStartElement("rss")
xFeed.WriteAttributeString("version", "2.0")
xFeed.WriteStartElement("channel")
xFeed.WriteElementString("title", "Online Casino Latest Games Releases")
xFeed.WriteElementString("link", "http://localhost:1218/MyRSS/Default.aspx")
xFeed.WriteElementString("description", "The latest Casino News from around the world")
xFeed.WriteElementString("copyright", "Copyright 2001 - 2009 Roxy Palace Casino")
xFeed.WriteElementString("language", "en-us")
xFeed.WriteElementString("guid", "http://www.roxypalace.com/Winston.aspx?guid=1234")
'testing image 6 lines below
xFeed.WriteStartElement("image")
xFeed.WriteElementString("url", "http://www.roxypalace.com/games/EN/Slots/Crazy_Chameleons.gif")
xFeed.WriteElementString("title", "RoxyPalaceGamesImage")
xFeed.WriteElementString("link", "http://www.roxypalace.com")
xFeed.WriteElementString("description", "This shows up in title of link around image")
xFeed.WriteEndElement()
Dim MySqlConection As SqlConnection
MySqlConection = New SqlConnection("Data Source=WINSTONH\SQLExpress;Initial Catalog=RSSInfo;Integrated Security=True")
Dim MySqlCommand As SqlCommand
MySqlCommand = New SqlCommand("FeedInfo", MySqlConection)
MySqlCommand.CommandType = Data.CommandType.StoredProcedure
Dim MySqlDataReader As SqlDataReader = Nothing
If MySqlConection.State = Data.ConnectionState.Closed Then
MySqlConection.Open()
MySqlDataReader = MySqlCommand.ExecuteReader
End If
While MySqlDataReader.Read
xFeed.WriteStartElement("item")
xFeed.WriteElementString("title", MySqlDataReader("Title").ToString)
xFeed.WriteElementString("description", MySqlDataReader("Description").ToString)
xFeed.WriteElementString("link", "http://"
Oops my post got cut off above...
While MySqlDataReader.Read
xFeed.WriteStartElement("item")
xFeed.WriteElementString("title", MySqlDataReader("Title").ToString)
xFeed.WriteElementString("description", MySqlDataReader("Description").ToString)
xFeed.WriteElementString("link", "http://"
Oops my be problem with server cutting off content for some reason...3rd time lucky:
thanks dear, thats so useful ...
hgj
Plz tel me wat is the SP \"GetTodaysHeadlines\"... can u plz give me the procedure
could u plz tell me the Database structure and storedprocedure of sql database
send me a complete exmaple
can u send me the field u use in database..
complete example..
simply great.It helps me a lot
how can i get the xml output?
anyone know how to make the rss feed "link" open into another window?
xtwFeed.WriteElementString("link", "http://www.google.com")
Very good article
thanks
This is a really useful thread. One thing that I have not been able to acheive though is calling an XSLT stylesheet into this dynamic process. Any suggestions?
Thanks
I have gone through yur page.
After i finish all coding part i found I can not find how many people attache my web page as RSS feed.
Can u sujjest me how do I Count How many people are using my RSS feed??
Thanks.
Very good example. Had RSS working in 5 minutes thanks to this instead of the several hours it would have taken me to read though the standard.
Thanks
Hi ya, here is my vb code if it's any help
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports System.Xml
Partial Class rss_LatestNews
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Clear()
Response.ContentType = "text/xml"
Dim xtwFeed As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
xtwFeed.WriteStartDocument()
' The mandatory rss tag
xtwFeed.WriteStartElement("rss")
xtwFeed.WriteAttributeString("version", "2.0")
' The channel tag contains RSS feed details
xtwFeed.WriteStartElement("channel")
xtwFeed.WriteElementString("title", "yoursite News")
xtwFeed.WriteElementString("link", "http://www.yoursite.com")
xtwFeed.WriteElementString("description", "The latest news from Ashford Borough Council, Kent.")
xtwFeed.WriteElementString("copyright", "Copyright 2009 yoursite. All rights reserved.")
Dim TSQL As String = "YOUR SELECT QUERY"
' database Connection
Dim objConn As SqlConnection
Dim objCmd As SqlCommand
Dim objRdr As SqlDataReader
objConn = New SqlConnection(ConfigurationManager.ConnectionStrings("MyConnection").ConnectionString)
objCmd = New SqlCommand(TSQL, objConn)
objCmd.CommandType = CommandType.Text
objConn.Open()
objRdr = objCmd.ExecuteReader(CommandBehavior.CloseConnection)
While objRdr.Read()
xtwFeed.WriteStartElement("item")
xtwFeed.WriteElementString("title", Convert.ToString(objRdr("Title")).Trim())
xtwFeed.WriteElementString("description", Convert.ToString(objRdr("LongDesc")).Trim())
xtwFeed.WriteElementString("link", "http://www.yoursite.com/default.aspx?page="
Ahh it missed off the rest so here it is
While objRdr.Read()
xtwFeed.WriteStartElement("item")
xtwFeed.WriteElementString("title", Convert.ToString(objRdr("Title")).Trim())
xtwFeed.WriteElementString("description", Convert.ToString(objRdr("LongDesc")).Trim())
xtwFeed.WriteElementString("link", "http://www.yoursite.com/default.aspx?page="
Nice article.
hi
I want to get the RSS feed automatically after sertain amount of time.... Without clicking on some button.. How to do that.
Pleaese help
with google chrome/safari seems this page don't work properly. do you have some suggestions?
I have been searching for just like a day and finally I found a solution being worth to be thanked ! Thanks a lot man !
Hey, thanks for posting such a good article, even though I am still having some problems, my bet. Anyway, thanks.
http://www.rsschannelwriter.com/
Emergency Soft has just released a new version of RSS Channel Writer. This comprehensive, yet easy-to-use software promises to be the most professional in its field.
Nice code and it is very easy to understand.Thanks for your good work.
Plz tel me wat is the SP \"GetTodaysHeadlines\"... can u plz give me the procedure
SP \"GetTodaysHeadlines\" is whatever you want it to be. It's just a call to a database stored procedure - you wouldn't use this call.
I follow your step, but my page http://www.bellafindings.com/TodaysHeadlines.aspx was error, here is a message error:
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
I don't know how to solve it, could you help me please?
Thanks,
Wesley.
If you want to buy a car, you would have to receive the <a href="http://lowest-rate-loans.com">loan</a>. Moreover, my brother commonly takes a collateral loan, which occurs to be the most firm.
Well i got good idea on rss now, keep it up good posting, so now i have a shopping site ill develop same as you said, and the site is http://couponmartonline.com
Well i got good idea on rss now, keep it up good posting, so now i have a shopping site ill develop same as you said, and the site is <a href='http://couponmartonline.com'> Shoping Site</a>
I received my first <a href="http://lowest-rate-loans.com/topics/credit-loans">credit loans</a> when I was not very old and that aided my family very much. But, I require the secured loan also.
I would like you to help me with the complete solution and schema as the my rss is not coming up
thank a lot.
i would like to help me how to give an rssfeed .how to write a code for rssfeed in 3-tier architecture in asp.net with c#
i would like to help me how to give an rssfeed .how to write a code for rssfeed in 3-tier architecture in asp.net with c#
All people deserve wealthy life and <a href="http://lowest-rate-loans.com/topics/home-loans">lowest-rate-loans.com</a> or student loan can make it better. Just because freedom is grounded on money.
Hello,
If some changes has been made on an old thread and published what will happen to this thread in RSS feed?
will this thread appear on the top of the RSS feed links or not??
Thanks
Hello,
If some changes has been made on an old thread and published what will happen to this thread in RSS feed?
will this thread appear on the top of the RSS feed links or not??
Thanks
Related Tutorials
Related Source Code
ASP.NET Job Search