Using ActiveReports with Iron Speed Designer
"With a little more work and imagination you could turn this into a very sophisticated looking and acting reporting mechanism. There are other reporting formats like Rich Text Format (RTF), Export to Excel and a lot more..."
- Miles Gibson, Consultant and Principal of Milestone Consulting

January 4, 2006
Introduction
These days there are many popular reporting tools available to the .NET world. The most popular is Crystal Reports by Business Objects. Next in line is either ActiveReports by Data Dynamics, or XtraReports by Developer Express, followed by a steady stream of others.

I have recently been working on a project for a client that required the use of a reporting tool to build graphs and reports. We looked at all of the above choices before settling on ActiveReports. This was for two reasons:

  1. no runtime licensing fees to use a WebViewer control
  2. really easy reporting
For this article I am going to focus on implementing a simple ActiveReports report into an Iron Speed Designer application.

Presumptions:

  • You have Iron Speed Designer Version 3.1 installed

  • You have Microsoft Visual Studio 2003 installed

  • You have ActiveReports Professional 2.0 .NET installed

Building ActiveReports
I created an Iron Speed Designer application against the Northwind database and have called this application 'Northwind'. I created this application in 'C:\Northwind'.

Step 1: Copy your ActiveReports file into the Iron Speed Designer application root directory if you already have one.

Step 2: Create a new layout page in Iron Speed Designer and name it "PreviewCustomersReport". You should save this page in a folder that is associated, in this case the Customers folder. You may also decide to store all of your reports in a common reports folder, really just personal choice. (I prefer keeping apples with apples.)

Step 3: Put in any menus or other controls that you want included on this page now. Save and build your application in Iron Speed Designer so that the PreviewCustomersReport.aspx file gets created by Iron Speed Designer.

Step 4: Open Visual Studio 2003 and select your Northwind.sln solution file. If you do not see a solution file, then select the file called 'Northwind.vbproj'.

Step 5: Select 'PreviewCustomersReport.aspx' from Visual Studio's Solution Explorer (usually on the right). Double click to see the layout.

NOTE: There should be a plus sign in front of PreviewReport.aspx. If you do not see this, then you need to change Visual Studio to 'Show All Files'. At the top of Solutions Explorer there is a small toolbar. One of the menu items on this toolbar will toggle 'Show All Files'. You can put the cursor over each menu item to see the tool tip so that you can find what you need.

Step 6: From your toolbox on the left, select 'ActiveReports 2.0' and then drag a WebViewer control over onto the surface of 'PreviewGraph'. Let's save at this point. Now we have embedded the ActiveReports WebViewer control necessary to display our report.

Step 7: Next, we want to reference a report to our WebViewer control. By default the first instance of our WebViewer control is named 'WebViewer1', the second WebViewer2 and so on. Open the Properties window if it is not open. Select the WebViewer1 control.

When looking at the Properties window you will see a property called 'Report'. You may have to scroll the properties windows up to the top to see this particular property.

When you first click on the dropdown arrow to select a report there may be nothing appearing. Be patient. I believe that .NET is looking for all .rpx reports in that folder. If indeed there are reports available to select they will show up (eventually). I have a very fast machine but it still seems to take a few seconds for reports to appear. Be patient. If you can click quickly on the drop down with no effect; then you most likely have no reports available to select.

If nothing appears in a few seconds, copy your ActiveReports report file into your Iron Speed Designer application root directory and repeat this step.

If you have not yet created an ActiveReports report; you can create one very easily with the ActiveReports Reports Wizard, located by clicking Tools-ActiveReports Wizard. After you have created your report, you will have to recompile this solution using Visual Studio so that your new report will appear in the drop down of the WebViewer report property. See below.

NOTE: Do not make the mistake of renaming your report after you referenced it to a WebViewer control. Otherwise you will likely have to delete the report reference and start over again after re-building your solution.

If you have already created an ActiveReports report elsewhere, simply drop it into your Iron Speed Designer application folder and refresh your Visual Studio project.

Step 8: Do a Save All in Visual Studio.

Step 9: Run your application from within Visual Studio. Did your report appear? If the WebViewer object appears but with no report, go back and repeat Step 6.

Troubleshooting

At this point if you go back to Iron Speed Designer and change anything in the PreviewCustomersReport, Iron Speed Designer changes the contents of the .ASPX page. The next time you open this page in Visual Studio you won't see your WebViewer object. So what can we do prevent us having to do this every time?

We have to tell Iron Speed Designer to remember to include our ActiveReports references the next time an .ASPX page gets generated for this layout page.

To this there are two steps that we have to perform:

Step 1: Return to your application in Iron Speed Designer. Select the PreviewCustomersReport layout page. Switch to ASPX mode. At the top of the ASPX page there are a number of lines highlighted in yellow. Look for a line very similar to this one:

Copy this line and click the HTML tab in Iron Speed Designer. At the top of the page there is a GEN:Template line. Insert the code above the GEN:Template tag as shown below:

Step 2: Click the ASPX tab again. Look a little ways down the page until you see the following:

Copy this text into the clipboard and click the HTML tab again.

Paste this code into the HTML pane. I added an HTML table to improve the layout. You may already have your special layout that you want to use.

Save and recompile your application in Iron Speed Designer. Run your application to see your report in action. Congratulations! You have successfully added ActiveReports into your Iron Speed Designer application.

See below the working report from within Iron Speed Designer.

Export to PDF
From here you can easily add a button to export this report into PDF format. Let's do that next.

Step 1: Insert an Iron Speed Designer button into the CustomerPreviewReport layout page. Click on the button. Look at the Quick HTML pane that is at the bottom of the screen. (if you can't see this, click View-HTML Quick View from the Iron Speed Designer menu.

Step 2: Name the button "Export to PDF". Click Ok. Build your Iron Speed Designer application so that your generated application knows about the name of this button.

Step 3: With our button selected, right-click and select 'Add Code Customization'.

Click next past the welcome screen if present. You should now see a list of available code customizations for this button:

Select 'Add custom' button and Handle its OnClick event. Click Next.

Select our ExportToPDF button and click Next. Then click Finish. Now your code framework has been inserted into the safe class for this layout page.

Now we need to include code to generate our PDF document from our ActiveReports report. First, however, we need to tell .NET about using ActiveReports. To do this, we need to put an Imports statement at the top of the safe class page as shown below:

Okay, now that this done, let’s move back down to the code that the wizard inserted. We want to type the following lines just after the phrase ' Add business logic for OnClick event.

So then our code block should look something like this:

Build your application in Iron Speed Designer again. This time, however, we note that there are errors. I take you in this direction because I want you to see what happens when we forget to add a required reference. In this case, the export library for ActiveReports is needed but has not been referenced in our Visual Studio project.

So why did we not get this error when we added our ActiveReports report? Well, .NET added the libraries we needed for the report when we dragged the WebViewer into our .ASPX page. But we didn’t get the chance to do that with our export to PDF code.

Okay, so back to Visual Studio we go. If you get a message like this:

Then just click ‘Yes to All’.

Now go over to Solutions Explorer in Visual Studio and expand the references area for our solution. You can do this by clicking on the plus sign. Note the ActiveReports references that have already been added for us.

Left click references. Then right-click references and select 'Add Reference'. Scroll down the list until you see Data Dynamics references. You may have to widen the column to see everything.

Select the Data Dynamics ActiveReports PDF Export Filter reference and click ‘Select’. Click Ok.

Now we have our reference!

Let’s rebuild our project:

And run our project. This time it should compile successfully.

And then you should see this:

With a little more work and imagination you could turn this into a very sophisticated looking and acting reporting mechanism. There are other reporting formats like Rich Text Format (RTF), Export to Excel and a lot more...Any report format contained within our WebViewer is fair game for our Export process.

Implementation
Everything we have done so far has been within the cozy and safe confines of our development environment. But I presume that you would eventually like to put something like this into production.

As many of you already know, this is not always a safe journey. There are often many differences between development and production. Let’s discuss some of the things that you have to do correctly to see your reports running properly in a production environment.

One of the first things that tripped me up when I started working with ActiveReports in a production was environment was getting the reports to appear within the WebViewer. The WebViewer would appear, but the report object would not render. Finally in desperation I read the help file.

There I was reminded that I needed to tell Microsoft IIS how to deal with ActiveReport report and graph objects.

See the help section on configuring HTTP Handlers. This is critical to a successful deployment.

In a future version I will walk you through using parameters and generating a chart from a data source.

Conclusion
You may download the sample project for this article at http://www.milestone.ca/ironspeed/ironspeedrocks.htm.
About the Author
Miles Gibson
Consultant and Principal of Milestone Consulting

Miles is the founder of Milestone Consulting and has been providing his clients with the right solutions for over twenty two years. He has been a Microsoft Certified Partner since 1998, and was the first person to offer formal Iron Speed Designer training. Miles has been mentoring Iron Speed customers for over two years and was recently named an Iron Speed MVP for his continued contribution to the Iron Speed community.

Contact the author.



  Privacy Statement