Run a Report with JSON Data in the .NET Embedded Engine
This tutorial will guide you through running a document with JSON data in the .NET Embedded Engine with C#. It will go over installing the .NET Embedded Engine, and setting up the code to run a report with JSON data.
Before installation of the .NET Embedded Engine, make sure you meet the requirements and have the necessary pre-requisites installed. Those can be found here.
Install the .NET Embedded Engine
There are two ways to install the .NET Embedded Engine.
- NuGet Package Manager
- Manual Installation with zip file
NuGet Package Manager
The first approach is to use NuGet Package Manager via Visual Studio to install the .NET Embedded Engine into your application. This approach is simple as you only need to reference the NuGet package to get started. Those steps can be found here.
Manual Installation with zip file
The other approach is referencing the .NET Embedded Engine by downloading the zip file which contains the necessary DLLs. These can be found on our downloads page here.
Once you have downloaded the zip file, extract the contents and reference the DLLs in your project. The steps to do this can be found here.
Setup the Properties
Once you have installed the .NET Embedded Engine, you will need to set up the necessary properties in the properties file so you can generate documents. In your project's config file you will need to add the WindwardReports section. This section will contain the properties related to document generation. The only property that is required to get started is the license. If this is empty you can still generate output, however it will contain a watermark.
To add your license key or any report properties, you need to add a WindwardReports section to your projects .config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
.
.
<WindwardReports>
<add key="license" value="[[LICENSE]]"/>
</WindwardReports>
.
.
</configuration>
To learn more about the different properties we provide for report generation, check out this article.
Generating a Document
Now that you have the .NET Embedded Engine installed and the properties set up, you can start generating documents. Below is an example of how to generate a document with JSON data.
using System.IO;
using net.windward.api.csharp;
using WindwardInterfaces.net.windward.api.csharp;
namespace RunReportJson
{
class RunReportJson
{
static void Main(string[] args)
{
// Initialize the engine
Report.Init();
// Open template file and create output file
FileStream template = File.OpenRead("JSON - Template.docx");
FileStream output = File.Create("Report.pdf");
// Create pdf report process
Report myReport = new ReportPdf(template, output);
// Connect to our JSON database
IReportDataSource data = new JsonDataSourceImpl("http://json.windward.net/Northwind.json",
JsonDataSourceImpl.MODE.CONNECTION_STRING);
// Run the report process
myReport.ProcessSetup();
// The second parameter is the user given name of the data source in the template
myReport.ProcessData(data, "JsonData");
myReport.ProcessComplete();
// Close out of our template file and output
output.Close();
template.Close();
// Opens the finished report
string fullPath = Path.GetFullPath("Report.pdf");
System.Diagnostics.Process.Start(fullPath);
}
}
}