| |
| I browse the MSDN web site and its associated links
every day to see if new content has been posted. The set of sites
that I browse at the MSDN site include the various sites of VS.NET
and the .NET Framework. Over time, I realized that this browsing was
taking a lot of my time as I had to click between pages to find the
information that I wanted. In trying to think about a solution to
avoid this repeated scanning, I came across the new feature introduced
at MSDN, called RSS Feeds. This feed is an XML file that contains
the list of latest articles published at the MSDN site, which can
be downloaded. The XML contains a well-defined XML format that can
be easily parsed and displayed. The following article is a culmination
of my work with the RSS Feeds from MSDN and an application that uses
ASP.NET to display the feeds in a user-friendly manner. |
| |
| At the grass roots level, you can define RSS as "a
format for syndicating news and the content of news sites". You
can find more information about RSS at http://www.xml.com/pub/a/2002/12/18/dive-into-xml.html.
At the MSDN site, Microsoft has launched RSS feeds for the following
categories: |
| |
| |
MSDN Just Published. |
| |
Visual Studio. |
| |
Visual Basic. |
| |
Web Services. |
| |
Visual C#. |
| |
Visual C++. |
| |
.NET Framework and the CLR. |
|
| |
| Eack of these feeds contain information about the
latest articles that have been published. So, using this information,
I set the following goals for my ASP.NET project: |
| |
| |
The application will
only process the RSS feeds from the MSDN site. This was done
so that I will not worry about the RSS versions (MSDN uses version
2.0) and rather concentrate only on what I need. |
| |
The feeds from the various sites,
will be downloaded by a seperate .NET application that can be
scheduled. The files thus downloaded will be available in a
convenient location for the ASP.NET page. |
| |
An ASP.NET page will use a datagrid
to paginate the display from the various feeds. |
| |
We will use the caching feature
of ASP.NET to cache the feeds and update them only when the
file itself changes. This is called a dependency cache. |
|
| |
| The resultant application looks like the following: |
| |
 |
| |
| The following are the main highlights of the application: |
| |
| |
The header is a user
control that displays the relevant information. By using a user
control, I can reuse the same layout in other web projects.
|
| |
The combo box lists the various
feeds that are available. By using the [Show Latest] button,
the information in the feed can be viewed. |
| |
The grid displays information
from the feed XML. The user can use the various page number
to navigate to the desired page. Clicking on the link of an
article, takes you to that article. |
|
| |
| The program achieves good performance by using the
Cache object of ASP.NET. In this program, I've implemented
a caching method called dependency cache, which basically
ties the cache entries to some object that can change. In our case,
each time the feed XML changes, the cache is also updated. Here is
the source code that does this work. The cacheStatus is a label object
in the ASP.NET page that displays information regarding where the
file was fetched from. You can experiment with this and see for yourself
as to how the cache works. |
| |
If (IsNothing(Cache(strCacheEntry)))
Then
oDs = New DataSet
oDs.ReadXml(strFileName) '
Create the dependency cache and store the dataset
oDependency = New CacheDependency(strFileName)
Cache.Insert(strCacheEntry, oDs,
oDependency) cacheStatus.Text
= String.Format("{0} Now cached", strFileName)
Else
oDs = CType(Cache(strCacheEntry),
DataSet)
cacheStatus.Text = String.Format("{0}
Fetched from cache", strFileName)
End If |
|
| |
| We also talked about the application that fetches
the various feeds in a scheduled fashion. Here is the program that
does the same (I've included the source code for the application in
the download, but am discussing the same here). |
| |
Imports System.Xml Module
RSSFeedManager
' This module is responsible for
communicating with the various feed locations
' and then fetching the XML into
the location used by the feed application
Sub Main()
LoadAndSaveFeed("http://www.msdn.microsoft.com/rss.xml",
"MSDN Just Published.xml")
LoadAndSaveFeed("http://www.msdn.microsoft.com/vstudio/rss.xml",
"Visual Studio.xml")
LoadAndSaveFeed("http://www.msdn.microsoft.com/vbasic/rss.xml",
"Visual Basic.xml")
LoadAndSaveFeed("http://www.msdn.microsoft.com/vcsharp/rss.xml",
"Visual CSharp.xml")
LoadAndSaveFeed("http://www.msdn.microsoft.com/visualc/rss.xml",
"Visual CPlus.xml")
LoadAndSaveFeed("http://www.msdn.microsoft.com/netframework/rss.xml",
"NET Framework and CLR.xml")
LoadAndSaveFeed("http://www.msdn.microsoft.com/webservices/rss.xml",
"Web Services.xml")
End Sub
' This routine contacts the feed site and saves the same into
the location pointed
' by fileName
Sub LoadAndSaveFeed(ByVal url
As String, ByVal fileName As String)
Dim
oXml As XmlDocument
Dim
strFile As String oXml
= New XmlDocument
strFile
= Environment.CurrentDirectory & "\" & fileName
Try
oXml.Load(url)
oXml.Save(strFile)
Catch
ex As Exception
Console.WriteLine(ex.Message)
End
Try
Console.WriteLine("Fetched
From [{0}], Dumped Into [{1}]", url, strFile)
End Sub
End Module |
|
| |
| The code is very simple. We just use the XMLDocument
object and supply it the URL of the feed. After the XML is fetched,
it is saved to the location indicated. One important thing to note
about the application is the usage of the .config file that specifies
the policy to use for network access. By setting the usesystemdefault
value to "false", we do not ask .NET to use the IE default.
This EXE application can be scheduled by using the Windows scheduler.
For example, you can configure the application to download the feeds
everyday at 11 AM. The application also has a config file called RSSFeedManager.Exe.Config
that contains an override to the defaultProxy setting. I have set
the usesystemdefault setting to "false" so that no IE settings
are used. If you inside a proxy server, you will need to edit this
config file appropriately. For an example of this setting, see the
machine.config file (under defaultProxy). |
| |
| I've included the entire source code for the application
for you to download and experiment. When you download the ZIP file,
use the "Use Folder Options" option to unzip the same. You
will now get the following folder structure: |
| |
 |
| |
| The following is a brief description of the contents
of the folder: |
| |
| |
The RSSFeed is the
main application and the ShowFeed.aspx is the home page. |
| |
The Feeds sub-directory contains
the various feed XML files. It also has the RSSFeedManager EXE
application that downloads the various feeds. You need to schedule
this EXE file if need be. |
| |
The RSSFeedManager is the source
code for the EXE file. |
|
| Here are some of my thoughts on what other features
can be added to the application to make it more reusable (I will also
be working on these features, thus you can expect the next version
of this application sometime!!) |
| |
| |
Storing the list of
feeds in an XML file and loading the combo box from the same.
This will allow you to extend the feed list later on. |
| |
Allowing the user to sort on the
grid. |
| |
Allowing the various feeds to
be scheduled in various times. Right now, the EXE application
downloads all of them at the same time. |
| |
Notification feature to intimate
users that new content has arrived on the download. You can
find a version of such an application here, written by Dare
Obasanjo. |
|
| |
| I've found this application to be really useful and
use it very often these days. I also think it would be useful in organizations
where the internet access is limited to a few machines. These machines
can host this application and allow other users to access the local
site for the latest news, this reducing the bandwidth too. |
| |
| Download the source
code |
| |
| Have fun!! |
| |
| |