# Load Reports

This topic explains how to load and display a report using the Viewer control in a WPF application.

## Content

To load and display a report using the Viewer control in a WPF application,

1. Create a new a WPF application in Visual Studio.
2. From the Visual Studio toolbox, drag the **Viewer** control onto your XAML Form.
3. Set the viewer's **Dock** property to **Fill** to show the complete Viewer control on the Form.
4. In the Solution Explorer, select the report you have created and from the Properties window, set **Copy to Output Directory** to **Copy Always**.
5. On MainWindow.xaml, with the viewer selected, go to the Properties window and double click the Loaded event.
6. In the MainWindow code view that appears, add code like the following to the viewer1\_loaded event to bind the report to the viewer.

>type=note
> **Note:** The viewer control name you use in your code behind **must match** the value of the `x:Name` attribute, defined in your XAML.
> For example, if your XAML contains
>
> ```xml
> <Wpf:Viewer x:Name="ReportViewer" />
> ```
>
> then in your code-behind you must reference the control as:
>
> ```csharp
> ReportViewer
> ```

### Load RDLX-based report

This code shows an .rdlx report being loaded, but you can use an .rpx report file as well.

```csharp
ReportViewer.LoadDocument("rptSingleLayout.rdlx");
```

```vbnet
ReportViewer.LoadDocument("rptSingleLayout.rdlx")
```

### Load Snapshot

The sample code below shows how to load your RDLX-based report directly from a snapshot. See [Working with Snapshots](/activereportsnet/docs/v20.1/developers/working-with-reports-devs/page-rdl-report-developers/working-with-snapshots) for details.

```csharp
ReportViewer.LoadDocument(@"C:\Temp\Report1.rdlx-snap"); 
```

```vbnet
ReportViewer.LoadDocument("C:\Temp\Report1.rdlx-snap") 
```

To load a snapshot from a page document, use the code as follows.

```csharp
using System.IO;

var doc = PageDocument.LoadSnapshot(new FileInfo("C:\\Temp\\Report1.rdlx-snap"));
ReportViewer.LoadDocument(doc);
```

```vbnet
Imports System.IO

' Create a FileInfo object for the snapshot file
Dim snapshotFile As New FileInfo("C:\Temp\Report1.rdlx-snap")
' Load the snapshot into a PageDocument
Dim doc = PageDocument.LoadSnapshot(snapshotFile)
' Show the document in the viewer control
ReportViewer.LoadDocument(doc)
```

### Load Code-based Section Report

```csharp
var report = new MySectionReport();
ReportViewer.LoadDocument(report);
```

```vbnet
Dim report As New MySectionReport()
ReportViewer.LoadDocument(report)
```

### Load XML-based Section Report

```csharp
var xmlReport = new SectionReport();
xmlReport.LoadLayout(new FileInfo(@"C:\Reports\Invoice.rpx"));
ReportViewer.LoadDocument(xmlReport);
```

```vbnet
Dim xmlReport As New SectionReport()
xmlReport.LoadLayout(New FileInfo("C:\Reports\Invoice.rpx"))
ReportViewer.LoadDocument(xmlReport)
```

>type=note
> **Note**: If Page/RDLX report is selected from dropdown of Source property (containing relative path), 'Copy to Output Directory' for selected report should be set as 'Copy always/Copy if newer' otherwise error "Could not find file ... " appears on loading WPF Viewer.

>type=warning
> **Caution**: In WPF Viewer control, previewing code-based Section reports using [Source](/activereportsnet/api/v20.1/MESCIUS.ActiveReports.Viewer.Wpf/GrapeCity.ActiveReports.Viewer.Wpf.Viewer.html) and  [SourceFormat](/activereportsnet/api/v20.1/MESCIUS.ActiveReports.Viewer.Wpf/GrapeCity.ActiveReports.Viewer.Wpf.Viewer.html) properties is not supported.

>type=note
> **Note**:
>
> * Refer to the [LoadDocument](/activereportsnet/api/v20.1/MESCIUS.ActiveReports.Viewer.Wpf/GrapeCity.ActiveReports.Viewer.Wpf.Viewer.html) method to see other ways to load a report in WPF Viewer.
> * We can set report for WPFViewer directly on XAML file and load the report in WPF Viewer using [Source](/activereportsnet/api/v20.1/MESCIUS.ActiveReports.Viewer.Wpf/GrapeCity.ActiveReports.Viewer.Wpf.Viewer.html) and [SourceFormat](/activereportsnet/api/v20.1/MESCIUS.ActiveReports.Viewer.Wpf/GrapeCity.ActiveReports.Viewer.Wpf.Viewer.html) properties.
> * To avoid evaluation banners appearing at run time, license your ActiveReports WPF Application project. You can find information on licensing in [License Your ActiveReports](/activereportsnet/docs/v20.1/developers/ar-how-licensing-activereports).

### See Also

[Samples](/activereportsnet/docs/v20.1/samples/samples-ar)