Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
After you have created your project and generated the classes from the RDL schema, you are ready to load a report definition from the report server.
To load a report definition
Add a private field at the top of the ReportUpdater class (module if you are using Visual Basic) for the Report class. This field will be used to maintain a reference to report that is loaded from the report server for the life of the application.
private Report _report;
Private m_report As Report
Replace the code for the LoadReportDefinition() method in the Program.cs file (Module1.vb for Visual Basic) with the following code:
private void LoadReportDefinition() { System.Console.WriteLine("Loading Report Definition"); string reportPath = "/AdventureWorks 2012 Sample Reports/Company Sales 2012"; // Retrieve the report defintion // from the report server byte[] bytes = _reportService.GetItemDefinition(reportPath); if (bytes != null) { XmlSerializer serializer = new XmlSerializer(typeof(Report)); // Load the report bytes into a memory stream using (MemoryStream stream = new MemoryStream(bytes)) { // Deserialize the report stream to an // instance of the Report class _report = (Report)serializer.Deserialize(stream); } } }
Private Sub LoadReportDefinition() System.Console.WriteLine("Loading Report Definition") Dim reportPath As String = _ "/AdventureWorks 2012 Sample Reports/Company Sales 2012" 'Retrieve the report defintion 'from the report server Dim bytes As Byte() = _ m_reportService.GetItemDefinition(reportPath) If Not (bytes Is Nothing) Then Dim serializer As XmlSerializer = _ New XmlSerializer(GetType(Report)) 'Load the report bytes into a memory stream Using stream As MemoryStream = New MemoryStream(bytes) 'Deserialize the report stream to an 'instance of the Report class m_report = CType(serializer.Deserialize(stream), _ Report) End Using End If End Sub
Next Lesson
In the next lesson, you will write code to update the report definition that was loaded from the report server. See Lesson 4: Update the Report Definition Programmatically.
See Also
Tasks
Updating Reports Using Classes Generated from the RDL Schema (SSRS Tutorial)