Skip to content

Export Without GUI

Peter Gill edited this page Jun 8, 2026 · 3 revisions

This code demonstrates the basics of loading a report with no GUI and exporting to various file formats.

For the full list of supported output types see Output Formats. For streaming output to an HTTP response without writing to disk see Streaming PDF — ASP.NET Core.

Export to PDF

This requires the following nuget packages.

dotnet add package Majorsilence.Reporting.RdlEngine
dotnet add package Majorsilence.Reporting.RdlCri

# or

dotnet add package Majorsilence.Reporting.RdlEngine.SkiaSharp
dotnet add package Majorsilence.Reporting.RdlCri.SkiaSharp

Reads an RDL file, parses it, runs the data query, and exports to PDF.

using System;
using Majorsilence.Reporting.Rdl;

namespace NoGuiExample
{
    class Program
    {
        static async Task Main(string[] args)
        {
            // One time per app instance
            RdlEngineConfig.RdlEngineConfigInit();

            var rpt = await GetReport(new Uri(@"C:\The\Report\Directory\SimpleTest1.rdl"));
            await SaveReport(@"C:\The\Report\Directory\simpletest1.pdf", rpt);
        }
        private static async Task SaveReport(string savePath, Report rpt)
        {
            await rpt.RunGetData(null);
            var sg = new Majorsilence.Reporting.Rdl.OneFileStreamGen(savePath, true);
            await rpt.RunRender(sg,  OutputPresentationType.PDF);
        }

        private static async Task<Report> GetReport(Uri sourcefile)
        {
            var reportSource = await System.IO.File.ReadAllTextAsync(sourcefile.AbsolutePath);
            var rdlp = new RDLParser(reportSource);
            var r = await rdlp.Parse();

            if (r.ErrorMaxSeverity > 0)
            {
                foreach (string emsg in r.ErrorItems)
                {
                    Console.WriteLine(emsg);
                }

                int severity = r.ErrorMaxSeverity;
                r.ErrorReset();
                if (severity > 4)
                {
                    r = null; // don't return when severe errors
                }
            }

            return r;
        }
    }
}

Export to Excel, CSV, HTML and other formats

Change the OutputPresentationType and output file path. All other code stays the same.

using Majorsilence.Reporting.Rdl;

RdlEngineConfig.RdlEngineConfigInit();

var rdlp = new RDLParser(await System.IO.File.ReadAllTextAsync(@"C:\reports\report.rdl"))
{
    Folder = @"C:\reports"
};
using var report = await rdlp.Parse();

if (report.ErrorMaxSeverity > 4)
    return; // see Error-Handling wiki page

await report.RunGetData(null);

// Excel workbook (full formatting)
using var xlsx = new OneFileStreamGen(@"C:\output\report.xlsx", true);
await report.RunRender(xlsx, OutputPresentationType.Excel2007);

// Excel — data rows only, no report chrome
using var xlsxData = new OneFileStreamGen(@"C:\output\report-data.xlsx", true);
await report.RunRender(xlsxData, OutputPresentationType.Excel2007DataOnly);

// CSV
using var csv = new OneFileStreamGen(@"C:\output\report.csv", true);
await report.RunRender(csv, OutputPresentationType.CSV);

// HTML
using var html = new OneFileStreamGen(@"C:\output\report.html", true);
await report.RunRender(html, OutputPresentationType.HTML);

// RTF
using var rtf = new OneFileStreamGen(@"C:\output\report.rtf", true);
await report.RunRender(rtf, OutputPresentationType.RTF);

// Multi-page TIFF
using var tif = new OneFileStreamGen(@"C:\output\report.tif", true);
await report.RunRender(tif, OutputPresentationType.TIF);

Clone this wiki locally