ActiveReports 10 Server User Guide
Downloading a Code-Based Section Report
ActiveReports 10 Server User Guide > Samples and Walkthroughs > Walkthroughs > Downloading a Code-Based Section Report

You can download the reports uploaded in the ActiveReports Server using the Download method and can save it into report definition format. This topic explains how to download a code-based section report (XML) to PDF format.

Note: You can also download a page report or an RDL report using the same steps.
  1. From the Visual Studio File menu, select New Project.
  2. In the New Project dialog that appears, select Visual C# or Visual Basic from the template list, click Windows and select Console Application.
  3. Rename the project to RenderReport and сlick OK.
    Note: The target framework of the project must be set to .NET Framework 4.5 or above.
  4. From the Visual Studio Project menu, select Add Service Reference.
  5. In the Add Service Reference dialog that appears, enter the following address in the Address field.
    Paste in the Address box, replacing 8080 with the site port where you installed ActiveReports Server.
    Copy Code
    http://localhost:8080/ReportService.svc
  6. Click Go, and when the ReportService appears in the Services pane, you can expand it and select the service interface to reveal its available operations in the pane to the right.
  7. Rename the Namespace that you want to use to ReportService and click OK. The reference appears in the Solution Explorer.
  8. Open the app.config file, in the address attribute of endpoint element, check if the service address set in step 5 is correct. Replace the address if it is not correct. 
    confirm the value of address attribute in the endpoint element of app.config file
    Copy Code
    <client>
    <endpoint address="http://localhost:8080/ReportService.svc"
    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IReportService"
    contract="ReportService.IReportService" name="WSHttpBinding_IReportService" />
    </client>
    Note: The service address may not get update automatically by the server configuration of the installed ActiveReports Server.
  9. In the app.config file, add maxReceivedMessageSize attribute inside the binding element and set appropriate value. If you want to send or receive large amount of data in WCF service, you need to customize this value. In the following example, the value is set to 10 MB. 
    Add INSIDE the binding element of app.config file
    Copy Code
    <bindings>
        <wsHttpBinding> 
            <binding name="WSHttpBinding_IReportService" maxReceivedMessageSize="10000000"> 
                <security mode="None" />
                    </binding> 
            </wsHttpBinding> 
    </bindings>
    
  10. In Program.cs or Module1.vb, add the following statements to the using/Imports statements at the top of the code.

    Visual Basic

    Visual Basic code (Add to the list of Imports statements at the top of the code.)
    Copy Code
    Imports System.IO
    Imports DownloadReport.ReportService

    C#

    C# code(Add to the list of using statements at the top of the code.)
    Copy Code
    using System.IO;
    using DownloadReport.ReportService;
  11. In Program.cs or Module1.vb, add the following code into the Main method.

    Visual Basic

    Visual Basic code (Paste the following code into the Main method of the Module1 module declaration)
    Copy Code
    Dim serverUserName As String = "USER"
    Dim serverUserPwd As String = "PASS"
    Dim reportService As New ReportServiceClient("WSHttpBinding_IReportService")
    ' Get the security token using Login method
    Dim securityToken As String = reportService.Login(serverUserName, serverUserPwd, Nothing, True)
    ' Get the list information of the uploaded form
    Dim query As New ReportService.Query()
    Dim description As ReportDescription() = reportService.[Select](securityToken, query)
     
    
    ' Get the report description of the output target
    Dim TargetRepDescription As New ReportDescription
    For Each des As ReportDescription In description
    If des.Name = "Payment Slip" Then
    TargetRepDescription = des
    Exit For
    End If
    Next
    ' Get the encoded form data
    Dim result As DataResult = reportService.Download(securityToken, TargetRepDescription.Id)
    ' Return to byte array
    Dim s As String = result.Data
    Dim bs As Byte() = System.Convert.FromBase64String(s)

    ' Specify the target folder Dim outFileName As String = "C:\work\PaymentSlip.rpx" Dim outFile As New System.IO.FileStream(outFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write)
    outFile.Write(bs, 0, bs.Length)
    outFile.Close()

    C#

    C# code (Paste the following code into the Main method of the Program class declaration)
    Copy Code
    var serverUserName = "USER";
    var serverUserPwd = "PASS";
    var reportService = new ReportServiceClient("WSHttpBinding_IReportService");
    var securityToken = reportService.Login(serverUserName, serverUserPwd, null, true);
    // Get the report list from internal storage
    var description = reportService.Select(securityToken, new Query());
    // Get the report description of the output target
    ReportDescription TargetRepDescription = new ReportDescription();
    foreach (var des in description)
    {
    if (des.Name == "Payment Slip")
    {
    TargetRepDescription = des;
    break;
    }
    }
    // Get the encoded form data 
    var result = reportService.Download(securityToken, TargetRepDescription.Id);
    // Return to byte array
    string s = result.Data;
    byte[] bs = System.Convert.FromBase64String(s);
    // Specify the target folder                                      
    string outFileName = @"C:\work\PaymentSlip.rpx";
    System.IO.FileStream outFile = new System.IO.FileStream(outFileName,
    System.IO.FileMode.Create, System.IO.FileAccess.Write);
    outFile.Write(bs, 0, bs.Length);
    outFile.Close();
     
    
  12. Run the project.