We're pleased to launch FlexViewer for MVC, a new HTML5 report viewer supporting FlexReport and C1Reports. C1Studio's FlexReport has been a leap forward in our strong Reporting & Documentation offering, and the FlexViewer for MVC is a powerful addition to your .NET reporting capabilities. C1Studio's FlexReport for web consists of:
Update: The HtmlHelpers\TagHelpers for FlexViewer has been launched in 2016 V2. In addition an Item Template has also been released that enables integration of FlexReport Web API and FlexViewer in the same MVC5 or ASP.NET Core MVC(.Net framework) project. Please refer this blog for getting started with FlexViewer in MVC. You may also refer the documentation. In this tutorial, you'll learn how to:
The standalone FlexReport Designer app is installed at C:\Program Files (x86)\ComponentOne\Apps\4.0\. Here's a look at some resources for creating a report:
MVC FlexViewer Here's a quick look at the highlights of FlexViewer.
Let's walk through the steps required to view a report created using FlexReport Designer on the web. To view a FlexReport on the web, we require a Web API of FlexReport and a client HTML5 report viewer control. The FlexReport Web API consists of REST services with which the viewer communicates to load and display reports. The FlexReport Web API can be created in two ways:
If you've installed Web API Edition from C1Studio installer, then it's easy to create a project pre-configured with FlexReport Web API. Use the C1 Web API Template to create a new project named FlexReportWebAPI and follow steps below:
Change connection string for local DB inside report definition
In the Startup.cs, add the following code inside Configuration method of the Startup class. This code registers the folder\location where the Report files will be stored; in this case, it's the Files folder:
app.UseCors(CorsOptions.AllowAll);
var folder = GetFullRoot("Files");
app.AddDiskStorage("root", folder);
You will need to add Microsoft.Owin.Cors package from NuGet to the project if it is not added.
Add the GetFullRoot function inside the Startup class:
private static string GetFullRoot(string root)
{
var applicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
var fullRoot = Path.GetFullPath(Path.Combine(applicationBase, root));
if (!fullRoot.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
{
fullRoot += Path.DirectorySeparatorChar;
}
return fullRoot;
}
Compile and deploy to IIS. If hosted on local IIS, the Web API url will be http://localhost/FlexReportwebAPI/.
Create a new ASP.NET Web API Project.
If you've installed MVC Edition, the GrapeCity NuGet source path should already be set inside Visual Studio. Alternatively, you could manually add the source path from Tools > NuGet Package Manager > Package Manager Settings as depicted in the following screen: GrapeCity Nuget Add ComponentOne ASP.NET Report Service package from GrapeCity NuGet.
Report WebAPI package FlexReport Web API adds the following C1 references to the project:
FlexReport WebAPI References
Add licensing to the project by creating a licenses.licx file inside the project. This file can be created by adding a text file and saving it as Licenses.licx. In this file, add the following entry:
C1.Web.Api.LicenseDetector, C1.Web.Api
Read more about MVC Licensing >>
Add NuGet package for Microsoft.Owin.Cors to support cross origin calls. Open the Startup.cs file and add the following code to Configuration method:
app.UseCors(CorsOptions.AllowAll); //support cross origin calls
var folder = GetFullRoot("Files"); //Map report files location
app.AddDiskStorage("root", folder);
You will need to add Microsoft.Owin.Cors package from NuGet to the project, you will also need to add the following namespaces to the startup:
using Microsoft.Owin.Cors;
using C1.Web.Api;
using System.IO;
Add the following GetFullRoot function to startup class:
private static string GetFullRoot(string root)
{
var applicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
var fullRoot = Path.GetFullPath(Path.Combine(applicationBase, root));
if (!fullRoot.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
{
fullRoot += Path.DirectorySeparatorChar;
}
return fullRoot;
}
Open web.config and add the following entry under handlers inside system.webServer Node:
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="api/*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
Deploy the project to IIS. If hosted on local IIS, the Web API url will be http://localhost/FlexReportwebAPI/.
The FlexViewer is currently a JavaScript control that can be used in a MVC application. Here's how to use the control to view a report.
Create a new ASP.NET MVC project using C1 MVC Template. Add a new scaffolded item to the project by right-clicking on the Controllers folder.
In the scaffolder wizard select MVC5 empty controller. In this example, we named the controller ReportTasksController.
Add a Scripts folder to the project. Add the following file to the project.
These files are available with the FlexViewer HowTo sample available at: ~\Documents\ComponentOne Samples\ASP.NET MVC\MVC\HowTo\FlexViewer\FlexViewer\Script
Add the flexviewer.css file to the content folder. This file can be found in the Contents folder of the above mentioned HowTo sample.
Add the images folder available in the HowTo FlexViewer sample's Content folder to this project.
Open the Index.cshtml under Views > ReportTasks. Add references to the JavaScript & stylesheet css files to the Index.cshtml.
Add the following script to load and view the "Simple List" report available in the "FlexCommonTasks.flxr" report definition file:
// c1.mvc.Utils.documentReady(function () {
loadFlexReport();
})
function loadFlexReport() {
var flexView = new wijmo.report.FlexViewer("#flexViewer")
var flexReport = new wijmo.report.FlexReport();
flexReport.serviceUrl = "http://localhost/FlexReportwebAPI/";
flexReport.reportUrl = '/root/FlexCommonTasks.flxr';
flexReport.reportName = "Simple List";
if (flexView.documentSource) {
flexView.documentSource.dispose();
}
flexView.documentSource = flexReport;
}
// ]]>
The loadFlexReport function does the following operations:
Run the project and navigate to ReportTasks to view the report. HTML5 Report Viewer
Note: FlexViewer for MVC, FlexReport Designer and FlexReport Web APIs are available to MVC Edition license holders, but the C1Studio Web APIs are available only in ComponentOne Studio and Ultimate.