OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Report generation using Fast Report with .Net Core 8

  • Thread starter Thread starter TechChoice
  • Start date Start date
T

TechChoice

Guest
I'm developing a .NET Core application in which I use FastReport to generate reports in PDF format.

I am providing a .frx file and a .json file, which acts as a data source compatible with the .frx file as a parameter. However, while binding data, it shows the static data used during the design of the .frx file instead of binding the dynamic data provided in the JSON file. Additionally, it should be capable of binding databands and child bands.

Does anyone have any idea how to resolve this? Your assistance would be greatly appreciated.

Here are a few snippets I've tried:

Code:
// Load the report
var report = new Report();
report.Load("path_to_your.frx");

// Load the JSON data
var jsonData = File.ReadAllText("path_to_your.json");

// Base64 encode the JSON data
string encodedJsonData = Convert.ToBase64String(Encoding.UTF8.GetBytes(jsonData));

// Register the JSON data source connection
RegisteredObjects.AddConnection(typeof(JsonDataSourceConnection));
JsonDataSourceConnection jsonDataSourceConnection = new JsonDataSourceConnection
{
    Name = "Connection",
    ConnectionString = $"Json={encodedJsonData};Encoding=utf-8"
};

// Create all tables from the JSON data
jsonDataSourceConnection.CreateAllTables(true);
report.Dictionary.Connections.Add(jsonDataSourceConnection);

// Prepare the report
 if (report.Prepare())
{
    FastReport.Export.Pdf.PDFExport export = new FastReport.Export.Pdf.PDFExport();
    export.ShowProgress = false;
    export.Subject = "Report Subject";
    export.Title = "Report Title";
    System.IO.MemoryStream memStream = new System.IO.MemoryStream();
    report.Report.Export(export, memStream);
    report.Dispose();
    export.Dispose();
    memStream.Position = 0;

    return File(memStream, "application/pdf", "Report_" + Guid.NewGuid() + ".pdf");
}
<p>I'm developing a .NET Core application in which I use FastReport to generate reports in PDF format.</p>
<p>I am providing a .frx file and a .json file, which acts as a data source compatible with the .frx file as a parameter. However, while binding data, it shows the static data used during the design of the .frx file instead of binding the dynamic data provided in the JSON file. Additionally, it should be capable of binding databands and child bands.</p>
<p>Does anyone have any idea how to resolve this? Your assistance would be greatly appreciated.</p>
<p>Here are a few snippets I've tried:</p>
<pre><code>// Load the report
var report = new Report();
report.Load("path_to_your.frx");

// Load the JSON data
var jsonData = File.ReadAllText("path_to_your.json");

// Base64 encode the JSON data
string encodedJsonData = Convert.ToBase64String(Encoding.UTF8.GetBytes(jsonData));

// Register the JSON data source connection
RegisteredObjects.AddConnection(typeof(JsonDataSourceConnection));
JsonDataSourceConnection jsonDataSourceConnection = new JsonDataSourceConnection
{
Name = "Connection",
ConnectionString = $"Json={encodedJsonData};Encoding=utf-8"
};

// Create all tables from the JSON data
jsonDataSourceConnection.CreateAllTables(true);
report.Dictionary.Connections.Add(jsonDataSourceConnection);

// Prepare the report
if (report.Prepare())
{
FastReport.Export.Pdf.PDFExport export = new FastReport.Export.Pdf.PDFExport();
export.ShowProgress = false;
export.Subject = "Report Subject";
export.Title = "Report Title";
System.IO.MemoryStream memStream = new System.IO.MemoryStream();
report.Report.Export(export, memStream);
report.Dispose();
export.Dispose();
memStream.Position = 0;

return File(memStream, "application/pdf", "Report_" + Guid.NewGuid() + ".pdf");
}
</code></pre>
Continue reading...
 

Latest posts

P
Replies
0
Views
1
Paul Gilmartin
P

Online statistics

Members online
0
Guests online
2
Total visitors
2
Ads by Eonads
Top