none
How to handle Sub Reports when using ReportViewer.ServerReport.LoadReportDefinition RRS feed

  • Question

  • Hi,

    I am trying to write an application that interacts with SSRS 2008 R2 using a Visual Studio 2010 ASP.Net Report Viewer Control.

    I have managed to get the Report Viewer control to connect to an instance of SSRS, and run a report using the ServerReport.LoadReportDefinition method.  This works OK, and the report is rendered by SSRS and displayed in the Report Viewer.

    What I can't figure out is how to handle sub reports in this.  The main report loaded by LoadReportDefinition may contain a subreport which would not exist on the server and would need to be loaded using the LoadReportDefinition.

    The reasons for needing to do this include:

    • Modifying the source SQL to look at different views and tables
    • Changing the text of the column headers etc based on configuration in the application

    The rough process that is done for each report would need to be similar to following (Works for report without a sub report)

    // Connect to report server
    ReportViewer1.ServerReport.ReportServerUrl = new Uri(sReportServerURL);
    
    // Load existing report contents from local file
    string sReportContents;
    using (StreamReader sr = File.OpenText(sReportFile))
    {
     sReportContents = sr.ReadToEnd();
    }
    
    // Replace datasource location with corrected location for SSRS
    sReportContents = sReportContents.Replace("<DataSourceReference>", "<DataSourceReference>/TESTING/");
    
    // Run process to replace SQL statement as required
    ReplaceReportSQL(sReportContents);
    
    // Run process to replace table headers etc. as required
    ReplaceReportConfig(sReportContents);
    
    // Convert report contents back to stream
    StringReader strRead = new StringReader(sReportContents);
    
    // Execute report
    ReportViewer1.ServerReport.LoadReportDefinition(strRead);
    

    Regards, 

    Richard Ward
    Software Developer
    Warwick International Computing Systems

    Tuesday, February 8, 2011 2:05 PM

All replies

  • Unfortunately, your scenario is not supported. If you're using ServerReport.LoadReportDefinition, all subreports need to be already published to the report server that's referenced.

    Please go to https://connect.microsoft.com/VisualStudio if you wish to make a feature suggestion to the ReportViewer team. Thank you.


    Cephas Lin This posting is provided "AS IS" with no warranties.
    Tuesday, February 8, 2011 6:00 PM
    Moderator