Navigation

Search

Categories

On this page

Developing an RSS Data Source - Part II
Developing an RSS Data Source - Part I
Just signed my offer letter

Archive

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 19
This Year: 10
This Month: 0
This Week: 0
Comments: 4

Sign In
Pick a theme:

 Friday, February 29, 2008
Friday, February 29, 2008 8:30:07 PM (GMT Standard Time, UTC+00:00) ( DNN | Reports Module )

UPDATE: Part III is now available.

In this series of blogs, I'm going to follow the development of an RSS Data Source. I'm going to use Visual Studio 2008, but I'll be using .Net 2.0 features so you should be able to follow along in Visual Studio 2005. You can also use the Express editions of Visual Web Developer (both 2005 and 2008 versions should work). All the code will be in VB.Net, but it should be straightforward enough for C# developers to understand (after all, its all .Net)

Continued from Part I.

Part II - WebRequests, XPath, and Data Tables, oh my!

In this part, we're going to add the code to retrieve data from the RSS feed. First, we need to create a folder to hold our code. We're going to put our code in the App_Code folder, so it will be compiled automatically by ASP.Net. That way we can save a few extra steps and get straight to the point. You could also put this code in a separate .Net Class Library, and put that library in the Bin folder of your website.

We'll create a sub-folder inside the App_Code folder for our code and call it RSSDataSource:

Creating an App_Code folder

Figure 1 - Creating an App_Code folder

Next, we need to tell ASP.Net to compile code found in this folder. Open the web.config file, in the root of the website, and find the <codeSubDirectories> section (its inside the <system.web> section). In my version of DotNetNuke it looks like this, but yours may have different <add> entries:

<codeSubDirectories>

  <add directoryName="HTML" />

</codeSubDirectories>

We need to add an entry to this list for our new subfolder. On my system, it looks like this (again, yours may vary slightly):

<codeSubDirectories>

  <add directoryName="HTML" />

  <add directoryName="RSSDataSource"/>

</codeSubDirectories>

Now that we have somewhere to put our code, let's create our Data Source! We'll create a class inside our nice new App_Code folder called RSSDataSource.

I'm not going to list the code for the Data Source in this post, because I've attached it to this post. However, I'll go over the general steps.

  1. First, we use the System.Net.WebClient class to download the RSS feed. For now, I've hardcoded it to one of my favourite blogs: Scott Hanselman's Computer Zen
  2. Next we create an ADO.Net DataTable with three columns: Title, Link and Description
  3. Then, we use the classes in the System.Xml.XPath namespace to add a row for each item in the feed to the DataTable.
  4. Finally, we wrap the DataTable in a DataView. The Reports Module expects us to return a DataView in order to allow us to do filtering and sorting if we wanted to. We aren't using that feature, so we just create a simple DataView to wrap our table.

There's only one last step to hook everything up. We need to tell the Reports Module how to find our Data Source code. To do that, open the code-behind file for DesktopModules/Reports/DataSources/RSS/Settings.ascx and change the DataSourceClass property to the following code:

Public ReadOnly Property DataSourceClass() As String Implements IDataSourceSettingsControl.DataSourceClass

    Get

        Return GetType(RSSDataSource).FullName

    End Get

End Property

And with that, we have a working RSS Data Source! Go back to your browser and go to the Settings page for the Reports Module instance we created in Part 1. Select the RSS Data Source as the Active Data Source, and click update. You should see a very wide grid containing the data from the RSS feed (assuming you are using the Grid Visualizer, which is the default):

Simple Grid View

Figure 2 - Simple Grid View

Well, that doesn't look very useful does it? Let's start by getting rid of that HTML junk in the Description field. To get rid of that, go back to the Settings page, and add "Description" to the list of columns to HTML Decode.

HTML Decode Converter

Figure 3 - HTML Decode Converter

That should clean up the HTML, but it's still a big grid. Let's use the HTML Visualizer to clean it up a bit. Put the following code in an HTML file and place it in your Portals/[PortalID] folder:

<h1><a href="[Link]">[Title]</a></h1>

[Description]

<hr />

Then, go back to the Settings page, select the HTML Template Visualizer and the HTML file you just uploaded:

Configuring the HTML Visualizer

Figure 4 - Configuring the HTML Visualizer

Click Update and you should see a much more readable display. It's almost like a real RSS Reader!

A Reports Module-powered RSS Reader?

Figure 5 - A Reports Module-powered RSS Reader!

Conclusion

Well, that's all for part two. Next, we'll cover Data Source settings so that we can point our Data Source at any RSS feed we want, rather than hard coding it. Then, we add an HTML Decoding feature directly into the Data Source so we don't have to configure the module to decode the Description field. Finally, we'll package it all up so that others can download and install it.

Download the code so far.

Comments [0] | | # 
Friday, February 29, 2008 6:03:39 AM (GMT Standard Time, UTC+00:00) ( DNN | Reports Module )

UPDATE: Part II is now available.

In this series of blogs, I'm going to follow the development of an RSS Data Source. I'm going to use Visual Studio 2008, but I'll be using .Net 2.0 features so you should be able to follow along in Visual Studio 2005. You can also use the Express editions of Visual Web Developer (both 2005 and 2008 versions should work). All the code will be in VB.Net, but it should be straightforward enough for C# developers to understand (after all, its all .Net)

Part I - Setting Up

First things first, you'll need to install a Source distribution of DotNetNuke. I'm not going to cover that here because there are some other resources out there. You'll also need to install the Source package of the Reports Module. Once you've done this, open your DotNetNuke website up in Visual Studio

Open Website Dialog

Figure 1 - Open Website Dialog

After opening it, expand the DesktopModules/Reports/DataSources folder. You should see something similar to the following

Data Sources Folder

Figure 2 - Data Sources Folder

Each of the folder under the DataSources folder represents a different Data Source. So, lets get started and create a folder for our Data Source and call it RSS. Inside that folder, we need to create an App_LocalResources folder. Visual Studio provides a special menu option to do that:

Add App_LocalResources Folder menu item

Figure 3 - Add App_LocalResources Folder menu item

Inside there, we must create a Resource file. Even if you aren't planning to translate your Data Source into different languages, the Reports Module uses this file to determine the name of your Data Source, so you must create it. In this sample, we aren't going to use the DotNetNuke Localization framework, so this is the only time we'll need to delve into Resource files. Add a new Resource file to the App_LocalResources folder called "DataSource.ascx.resx".

Adding a Resource File

Figure 4 - Adding a Resource File

Open this file and add a new resource key called "DataSourceName.Text" with a value of "RSS".

Editing the Resource File

Figure 5 - Editing the Resource File

We've almost got a running, albeit useless, Data Source. There's only one more file to add. Back in the "RSS" folder, add a Web User Control called "Settings.ascx". Open the Code-behind file (Settings.ascx.vb) and replace the contents with the following code:

Imports DotNetNuke.Modules.Reports.Extensions

Imports DotNetNuke.Modules.Reports.DataSources

 

Partial Class DesktopModules_Reports_DataSources_RSS_Settings

    Inherits ReportsSettingsBase

    Implements IDataSourceSettingsControl

 

 

    Public ReadOnly Property DataSourceClass() As String Implements IDataSourceSettingsControl.DataSourceClass

        Get

            Return String.Empty

        End Get

    End Property

End Class

Save everything and open your Web Browser. Add an instance of the Reports Module to a page and open the Settings page. You should now see the "RSS Data Source" in the Active Data Source drop-down. You can select it, but it doesn't do anything, so don't click Update.

Conclusion

That's all for part one. I know there isn't anything really useful yet, but I want to keep these parts short. Tomorrow, we'll add the code to retrieve data from an RSS feed.

Download the code so far.

Comments [0] | | # 
 Wednesday, February 13, 2008
Wednesday, February 13, 2008 6:54:27 AM (GMT Standard Time, UTC+00:00) ( Reports Module | Microsoft Internship )

Well, I just signed my offer letter so I'm going back to Microsoft for another summer! This time, I'll be working on the ASP.Net team, which is exciting. It's going to be a lot of fun having a chance to contribute to a framework I've been using for the past 2 years (I've almost forgotton what a Windows Form is :P).

I just thought I'd share that exciting news with my readers. However, I do have a few other updates:

  1. The Reports Module 5.0 User Guide is almost "content-complete" so I'll just need to get it formatted properly and it should be ready to go live
  2. I'm starting a Blog series on Developing for the Reports Module. For now, this is going to have to stand in for a full Programming Guide, but hopefully it will be a good starting point for those of you thinking of writing Visualizers or Data Sources.

Anyway, look for my first post in that series soon. I'll be crossposting it on my DotNetNuke blog, so feel free to check it out there.

Comments [0] | | # 

Search with Google

Google