Consume Rich Site Summary (RSS) files in ASP.NET
This ASP.Net code demonstrates how to simplify the consumption of an RSS document. The RSS data is provided by Wired Magazine (www.wired.com) and provides the daily news headlines for wired.com. For this example I have chosen to use the IPWorks .Net Edition RSS component to simplify the entire process.
Reading an RSS Feed
To begin with I have to start by creating the IPWorks object. I am also going to create a collection object to hold some information (more on that later).
Dim RSS1 as new nsoftware.IPWorks.RSS()
After creating the component I can call the GetFeed method, giving it the URL of the RSS Feed as an argument. The GetFeed method will provide the raw XML data of the RSS Feed in both the RSSData property as well as the Transfer event.
The component allows me to avoid sorting through the raw XML, and automatically parses the data for me. The RSS component provides several "Channel" and "Item" properties which provide information about the RSS feed itself, as well as the items in the feed.
In order to get the individual item information we can use the ItemCount property to iterate through the "Item" property arrays.
'Iterate through Item property arrays and output For i = 1 To RSS1.ItemCount Response.Write(SS1.ItemTitle(i) + ": " + RSS1.ItemPubDate(i) + _ "<P>" + RSS1.ItemDescription(i) + "<P>") Next
There are of course other Item properties, including ItemLink (a link to the full article text), as well as properties identifying the specifics about the feed itself.
Managing Your Own RSS Feed
Besides reading an RSS feed, the component will also allow you to add items to the feed. The AddItem method will actually add a new item in the Item property arrays, and the Put method will allow you to upload this new updated RSS feed to your web server.
To add a new item to the feed, simply call the AddItem method with the arguments Title, Description, and Link. These three arguments should be the values of the Title, Description of, and HTTP Link to your new item, respectively. For example:
RSS1.AddItem("New RSS Tutorial!", _ "There is a new RSS Tutorial available at the /n software KB.", _ "https://www.nsoftware.com/kb/rssasp.aspx")This is enough to add a new item, but it would be bare. It would only have a title, description, and link. You could add other properties to this item, such as:
RSS1.ItemPubDate(RSS1.ItemCount) = "Today's Date" RSS1.ItemAuthor(RSS1.ItemCount) = "Tom Smith" ... ...When I am finished with the new feed item, I would like to update my published RSS Feed on my website. To do this, since I am in an ASP.Net web application, I can simply overwrite the file:
RSSControl.WriteFile("/mywritefolder/myrssfeed.xml")I could also do this remotely by using the Put method of the component (Note: This will require appropriate permissions to be set on the server):
RSS1.AuthScheme = nsoftware.IPWorks.RssAuthSchemes.authDigest RSS1.User = "myusername" RSS1.Password = "mypassword" RSS1.Put("http://www.myserver.com/myrssfeed.xml")
As you can see, taking advantage of valuable web information can be easy to implement. A demo of the RSS component is included in all of the IPWorks Editions.
We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at email@example.com.