Export SSRS RDL Report in Bold Reports® UWP Report Writer

To export an SSRS RDL report in a UWP application, install the BoldReports.UWP package and use the Bold Reports® UWP Report Writer in your application. The Report Writer is a class library that exports RDL reports to popular file formats like PDF, Microsoft Word, Microsoft CSV, and Microsoft Excel without previewing the report. The following steps show how to export the RDL report in a UWP application using the Report Writer.

How do I create a UWP application for the Report Writer?

To create a UWP application for the Bold Reports® Report Writer, create a Blank App (Universal Windows) project in Visual Studio 2022.

  1. Open Visual Studio 2022 and click Create new project.

  2. Choose Blank App (Universal Windows), and then click Next.

    UWP application project template

  3. Change the project name, and then click Create.

  4. Select the target and minimum platform version from the dropdown, as in the following image, and then click OK.

    New universal windows platform project

Set the same version for the target and the minimum platform version.

How do I configure the Report Writer in a UWP application?

To configure the Report Writer in a UWP application, install the BoldReports.UWP NuGet package.

  1. Right-click the project or solution on the Solution Explorer tab and choose Manage NuGet Packages. Alternatively, select Tools > NuGet Package Manager > Manage NuGet Packages for Solution.

    Refer to the NuGet Packages to learn more details about installing and configuring the Report writer NuGet packages. You can add the reports from the Bold Reports® installation location. For more information, refer to the samples and demos section.

  2. Search for BoldReports.UWP NuGet package and install them in your UWP application.

    Package Purpose
    BoldReports.UWP Contains UWP Reporting controls (Report Writer) to preview and export the reports.

Adding already created report

This tutorial uses the Product List.rdlc report. Download the Product List report.

  1. Create a folder Resources in your application to store the RDLC reports.
  2. Add already created reports to the newly created folder.

Initialize Report Writer

  1. Initialize the Report Writer export type inside the <Grid> tag in the MainPage.xaml file:

    <Page
        ....
        ....
        ....
        xmlns:BoldReports="using:BoldReports.UI.Xaml"
        ....>
        <Grid Margin="0" Name="grd_controlPanel" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <StackPanel Name="pagePanel" Grid.Row="1" Margin="20,40,0,0" Background="White">
                <TextBlock  FontSize="15" FontFamily="Segoe UI Regular" TextWrapping="Wrap" Padding="5,5,5,5" >
                    <TextBlock.Text>This sample shows the capability of exporting a RDLC report into various file formats like PDF, WORD, EXCEL and HTML using Local export mode of Report Writer. Choose a file format and click generate button to view the selected document generated from report file.</TextBlock.Text>
                </TextBlock>
                <StackPanel Margin="0,10,0,0" Orientation="Vertical">
                    <RadioButton FontSize="15" FontFamily="Segoe UI Regular" Content="PDF" HorizontalAlignment="Left"  Margin="20,10,0,0" x:Name="pdf" IsChecked="true"  VerticalAlignment="Top"/>
                    <RadioButton FontSize="15" FontFamily="Segoe UI Regular" Content="Word" HorizontalAlignment="Left" Margin="20,10,0,0"  x:Name="word" VerticalAlignment="Top"/>
                    <RadioButton FontSize="15" FontFamily="Segoe UI Regular" Content="Excel" HorizontalAlignment="Left" Margin="20,10,0,0" x:Name="excel" VerticalAlignment="Top"/>
                    <RadioButton FontSize="15" FontFamily="Segoe UI Regular" Content="HTML" x:Name="html"  VerticalAlignment="Top" Margin="20,10,0,0" Width="90"/>
                    <Button Click="Button_Click" HorizontalAlignment="Left" Margin="20,10,0,0" VerticalAlignment="Bottom" BorderBrush="LightBlue" Background="#8bb54a">
                        <StackPanel Orientation= "Horizontal" Background="#8bb54a" Width="144">
                            <TextBlock Foreground="#ffffff" FontSize="16" FontFamily="Segoe UI Bold" Text="Generate"  HorizontalAlignment="Right" Margin="30,5,0,0" Width="110" VerticalAlignment="Center" Height="27"/>
                        </StackPanel>
                    </Button>
                </StackPanel>
            </StackPanel>
        </Grid>
    </Page>

Set Report Path

  1. Open the MainPage.xaml.cs file and add the following using statement.

    using BoldReports.Writer;
    using Windows.Storage.Pickers;
    using System.Reflection;
    using Windows.Storage.Streams;
    using Windows.Storage;
    using Windows.UI.Popups;
    using System.Collections;
  2. Create a class and methods that returns business object data collection. Use the following code in your application.

        public class ReportData
        {
            public string ProdCat { get; set; }
            public string SubCat { get; set; }
            public double? OrderYear { get; set; }
            public string OrderQtr { get; set; }
            public double? Sales { get; set; }
            public static IList GetData()
            {
                List<ReportData> datas = new List<ReportData>();
                ReportData data = null;
                data = new ReportData()
                {
                    ProdCat = "Accessories",
                    SubCat = "Helmets",
                    OrderYear = 2002,
                    OrderQtr = "Q1",
                    Sales = 4945.6925
                };
                datas.Add(data);
                data = new ReportData()
                {
                    ProdCat = "Components",
                    SubCat = "Road Frames",
                    OrderYear = 2002,
                    OrderQtr = "Q3",
                    Sales = 957715.1942
                };
                datas.Add(data);
                data = new ReportData()
                {
                    ProdCat = "Components",
                    SubCat = "Forks",
                    OrderYear = 2002,
                    OrderQtr = "Q4",
                    Sales = 23543.1060
                };
                datas.Add(data);
                data = new ReportData()
                {
                    ProdCat = "Bikes",
                    SubCat = "Road Bikes",
                    OrderYear = 2002,
                    OrderQtr = "Q1",
                    Sales = 3171787.6112
                };
                datas.Add(data);
                data = new ReportData()
                {
                    ProdCat = "Accessories",
                    SubCat = "Helmets",
                    OrderYear = 2002,
                    OrderQtr = "Q3",
                    Sales = 33853.1033
                };
                datas.Add(data);
                return datas;
            }
        }
  3. Initialize the ReportWriter by using the following code example in the MainPage.xaml.cs file export button click event.

        async void Button_Click(object sender, RoutedEventArgs e)
        {
            FileSavePicker fileSavePicker = new FileSavePicker();
            WriterFormat format = WriterFormat.PDF;
    
            if (pdf.IsChecked == true)
            {
                fileSavePicker.FileTypeChoices.Add("PDF", new List<string> { ".pdf" });
                fileSavePicker.DefaultFileExtension = ".pdf";
                format = WriterFormat.PDF;
            }
            else if (excel.IsChecked == true)
            {
                fileSavePicker.FileTypeChoices.Add("Excel", new List<string> { ".xlsx" });
                fileSavePicker.DefaultFileExtension = ".xlsx";
                format = WriterFormat.Excel;
            }
            else if (word.IsChecked == true)
            {
                fileSavePicker.FileTypeChoices.Add("Word", new List<string> { ".docx" });
                fileSavePicker.DefaultFileExtension = ".docx";
                format = WriterFormat.Word;
            }
            else if (html.IsChecked == true)
            {
                fileSavePicker.FileTypeChoices.Add("Html", new List<string> { ".html" });
                fileSavePicker.DefaultFileExtension = ".html";
                format = WriterFormat.HTML;
            }
    
            fileSavePicker.SuggestedFileName = "ExportReport";
            var savedItem = await fileSavePicker.PickSaveFileAsync();
    
            if (savedItem != null)
            {
                MemoryStream exportFileStream = new MemoryStream();
                Assembly assembly = typeof(MainPage).GetTypeInfo().Assembly;
                // Ensure the report loaction and application name.
                Stream reportStream = assembly.GetManifestResourceStream("<application name>.Resources.Product List.rdlc");
    
                BoldReports.UI.Xaml.ReportDataSourceCollection datas = new BoldReports.UI.Xaml.ReportDataSourceCollection();
                datas.Add(new BoldReports.UI.Xaml.ReportDataSource { Name = "Sales", Value = ReportData.GetData() });
    
                ReportWriter writer = new ReportWriter(reportStream, datas);
                writer.ExportMode = ExportMode.Local;
                writer.ExportCompleted += Writer_ExportCompleted;
                await writer.SaveASync(exportFileStream, format);
    
                try
                {
                    using (IRandomAccessStream stream = await savedItem.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        // Write compressed data from memory to file
                        using (Stream outstream = stream.AsStreamForWrite())
                        {
                            byte[] buffer = exportFileStream.ToArray();
                            outstream.Write(buffer, 0, buffer.Length);
                            outstream.Flush();
                        }
                    }
                    exportFileStream.Dispose();
                }
                catch { }
            }
        }
    
        private void Writer_ExportCompleted(object sender, byte[] e)
        {
            MessageDialog msgDialog = new MessageDialog("Report exporting completed successfully");
            msgDialog.ShowAsync();
        }
    • Build and run the application. Choose a file format and click the generate button to view the selected document generated from the report file.

    Congratulations! You have completed your first UWP Writer application! Download the completed UWP Report Writer application.

    Note: You can refer to our feature tour page for the UWP Report Writer to see its innovative features.

Frequently asked questions

Which formats can the UWP Report Writer export RDL reports to?

The Bold Reports® UWP Report Writer exports RDL reports to PDF, Microsoft Word, Microsoft CSV, and Microsoft Excel without previewing the report.

Which NuGet package do I install for the UWP Report Writer?

Install the BoldReports.UWP NuGet package in your UWP application. It contains the UWP reporting controls, including the Report Writer, to preview and export reports.