Working with FlexReport > Developing FlexReport for Desktop > Load FlexReport at Run Time |
Loading reports at run time requires a report definition file and a viewer. The main advantage of this type of application is that if you modify the report format, there's no need to update the application. Simply send the new report definition file to the users and you are done.
To create an application with reports loaded at run time, follow these steps:
Imports C1.WPF.FlexReport Imports System.IO
using C1.WPF.FlexReport; using System.IO;
This allows you to reference C1FlexReport and System.IO classes and objects without having to specify the full namespaces.
Private Sub btnRender_Click(sender As Object, e As EventArgs) ' get application path Dim appPath As String appPath = System.IO.Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly().Location).ToLower() Dim i As Integer = appPath.IndexOf(vbBack & "in") If(i < 0) Then i = appPath.IndexOf(vbBack & "in") End If If(i > 0) Then appPath = appPath.Remove(i, appPath.Length - i) End If ' get names of reports in the report definition file Dim m_ReportDefinitionFile As String = appPath & Convert.ToString("\Data\Products Report.flxr") Dim reports As String() = C1FlexReport.GetReportList(m_ReportDefinitionFile) ' populate combo box cmbReport.Items.Clear() For Each report As String In reports cmbReport.Items.Add(report) Next Try Cursor = System.Windows.Input.Cursors.Wait ' load report fv.StatusText = "Loading" + cmbReport.Text rep.Load(m_ReportDefinitionFile, cmbReport.Text) ' render into print preview control fv.StatusText = "Rendering" + cmbReport.Text fv.DocumentSource = rep ' give focus to print preview control fv.Focus() Finally Cursor = InlineAssignHelper(Cursor, System.Windows.Input.Cursors.Arrow) End Try End Sub
private void btnRender_Click(object sender, EventArgs e) { // get application path string appPath; appPath = System.IO.Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly().Location).ToLower(); int i = appPath.IndexOf("\bin"); if ((i < 0)) { i = appPath.IndexOf("\bin"); } if ((i > 0)) { appPath = appPath.Remove(i, appPath.Length - i); } // get names of reports in the report definition file string m_ReportDefinitionFile = appPath + @"\Data\Products Report.flxr"; string[] reports = C1FlexReport.GetReportList(m_ReportDefinitionFile); // populate combo box cmbReport.Items.Clear(); foreach(string report in reports) { cmbReport.Items.Add(report); } try { Cursor = System.Windows.Input.Cursors.Wait; // load report fv.StatusText = "Loading" + cmbReport.Text; rep.Load(m_ReportDefinitionFile, cmbReport.Text); // render into print preview control fv.StatusText = "Rendering" + cmbReport.Text; fv.DocumentSource = rep; // give focus to print preview control fv.Focus(); } finally { Cursor = Cursor = System.Windows.Input.Cursors.Arrow; } }
The code starts by getting the location of the file that contains the report definitions. This is done using static methods in the system-defined Path and Application classes. You may have to adjust the code to reflect the location and name of your report definition file.
Then it uses the GetReportList method to retrieve an array containing the names of all reports in the report definition file (created in step 1), and populates the combo box allowing users to select the report.