Walkthrough: Running a Report Offline
You can view a report and view the dataset and layout on a computer that does not have Microsoft Dynamics NAV installed. To do this, you must have Microsoft Visual Studio installed and you must export the report dataset from Microsoft Dynamics NAV as an .xml file and export the report layout .rdlc file from Visual Studio Report Designer.
Important
The dataset .xml file that you export contains actual data from the report. Do not share this file if you do not want to share actual database data.
About This Walkthrough
This walkthrough illustrates the following tasks:
Exporting the report dataset as an .xml file.
Copying the report layout .rdlc file.
Running the report by using Microsoft Visual Studio.
Prerequisites
To complete this walkthrough, you will need:
One computer with the following:
Microsoft Dynamics NAV 2015 with a developer license.
CRONUS International Ltd. demonstration database.
Microsoft Visual Studio installed. For more information about which version of Microsoft Visual Studio you need, see System Requirements for Microsoft Dynamics NAV 2013 R2. This walkthrough assumes that Microsoft Visual Studio 2012 or Microsoft Visual Studio 2013 is used.
A second computer with Microsoft Visual Studio.
Story
Viktor is a Microsoft Certified Partner working for CRONUS International. He is working on some enhancements to the Customer – Top 10 List report, but during his development phase, he has encountered some problems. Viktor wants to send the report to Microsoft Support to help him troubleshoot the problems. The Microsoft Support engineer wants to be able to view the report and report data offline instead of on a computer that has Microsoft Dynamics NAV installed. Viktor saves the report dataset and the report layout and sends them to the Microsoft Support engineer, who runs the report on his computer by using Visual Studio.
Saving the report dataset and layout
First, Viktor exports the report dataset to an .xml file.
To export the report dataset to an .xml file
On the computer with Microsoft Dynamics NAV installed, open the Microsoft Dynamics NAV Windows client.
In the Search box, enter Customer – Top 10 List, and then choose the related link.
On the request page for the Customer – Top 10 List report, on the Application menu , choose Help, and then choose About This Page to activate the About This Report feature. For more information, see How to: View and Export the Dataset for a Report.
Close the About This Page page.
On the request page for the Customer – Top 10 List report, choose Preview to open the Customer - Top 10 List report in Report Viewer.
On the report preview, on the Application menu , choose Help, and then choose About This Report to display the report dataset.
On the About This Report page, choose Export as XML.
In the Export File dialog box, choose Save.
In the Export File dialog box, navigate to your Desktop, enter Dataset for the file name, set the Save as type field to XML (*.xml), and then choose Save.
Next, Viktor must save the report layout as an .rdlc file.
To copy the report layout .rdlc file
In the development environment, choose Tools, and then choose Object Designer.
In Object Designer, choose Report, select report 111, Customer – Top 10 List, and then choose Design.
On the View menu, choose Layout to open the report layout in Visual Studio.
In Visual Studio, in Solution Explorer, select Report.rdlc, and then in the Properties window, note the path where the Report.rdlc file is located.
Tip
If the Properties window is not visible, then on the View menu, choose Properties.
Copy the Report.rdlc file from the location in the Properties window to your Desktop.
Viktor sends both the Dataset.xml file and the Report.rdlc file to the Microsoft Support engineer who is helping him troubleshoot the report.
Running the Report Offline
The Microsoft Support engineer has received the Dataset.xml file and the Report.rdlc file from Viktor and now runs the report on his computer by using Visual Studio.
Note
If the report references external assemblies, then you must install the assemblies in the global assembly cache on the computer on which you want to run the report. For more information, see EnableExternalAssemblies Property and Extending Microsoft Dynamics NAV Using Microsoft .NET Framework Interoperability,
To run the report by using Visual Studio
Copy the Dataset.xml file and Report.rdlc file from the first computer, which has Microsoft Dynamics NAV installed, to your desktop on the second computer, which does not have Microsoft Dynamics NAV installed.
On the second computer, open Visual Studio.
In Visual Studio, in the File menu, choose New, and then choose Project.
In the New Project window, under Installed Templates, expand Visual C#, choose Windows, and then choose Windows Forms Application.
Tip
If Visual C# is not listed under Installed Templates, then you must install the Visual C# feature. To do this, in Control Panel, choose Programs, choose Uninstall a program, select your version of Microsoft Visual Studio, and then choose Uninstall/Change. In the setup wizard, follow the instructions to add or remove features, and then choose the Visual C# feature.
In the Name field, enter OfflineReport, and then choose the OK button to create the solution.
In Solution Explorer, right-click the OfflineReport project, choose Add, and then choose Existing Item.
In the Add Existing Item dialog box, navigate to your Desktop, set the file type to All Files (*.*), select the Dataset.xml file and the Report.rdlc file, and then choose Add.
In Solution Explorer, under OfflineReport, select Dataset.xml. In the Properties window, in the Copy to Output Directory field, choose Copy Always from the drop-down list.
Tip
If the Properties window is not visible, then on the View menu, choose Properties.
In the Toolbox window, under Reporting, drag a new Report Viewer control to Form1.
Tip
If the Toolbox window is not visible, then on the View menu, choose Toolbox.
Note
You may need to resize the report viewer control or the form.
Select the report viewer control, and then in the Properties window, under Misc, expand Local Report, and then set the ReportEmbeddedResource property, to OfflineReport.Report.rdlc.
Note
If your report includes external images, then in the Properties window of the report viewer control, you must set the EnableExternalImages property to True.
Note
If your report includes hyperlinks, then in the Properties window of the report viewer control, you must set the EnableHyperlinks property to True. For examples of creating reports that include hyperlinks, see Walkthrough: Creating a Link from a Report to a Report and Walkthrough: Creating a Link from a Report to a Page.
In Solution Explorer, select the OfflineReport project, and on the shortcut menu, choose Add, and then choose Class.
In the Add New Item window, under Installed Templates, choose Visual C# Items, and then choose Class.
In the Name field, enter CreateDataSource.cs, and then choose Add.
In the CreateDataSource.cs tab, replace the code with the following.
using System.Data; namespace OfflineReport { public static class CreateDataSource { public static DataTable CreateTable() { DataSet dataSet = new DataSet(); dataSet.ReadXml("Dataset.xml"); return dataSet.Tables[0]; } } }
On the File menu, choose Save CreateDataSource.cs.
Choose the Form1.cs [Design] tab, and then on the View menu, choose Code.
In the Form1.cs tab, replace the code with the following.
using System; using System.Windows.Forms; using Microsoft.Reporting.WinForms; namespace OfflineReport { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet_Result", CreateDataSource.CreateTable())); this.reportViewer1.RefreshReport(); } } }
On the Build menu, choose Build Solution. The solution builds successfully.
On the Debug menu, choose Start Debugging to view the report in the report viewer control.
To make changes to the report layout, in Solution Explorer, right-click Report.rdlc, and then choose Open.
Tip
Now that you have created the OfflineReport solution, to run other reports from Visual Studio, you only need to replace the Dataset.xml and Report.rdlc files.