Viewing Report After Created Programmatically - C# MVC

6 posts, 0 answers
  1. Evan
    Evan avatar
    5 posts
    Member since:
    Aug 2014

    Posted 07 Oct 2014 Link to this post


    From the documentation, it doesn't seem hard to create a report programmatically: 

    Telerik.Reporting.Report report = new Telerik.Reporting.Report();
                string sql = @"SELECT * FROM Recipient";
                string connectionString = "Data Source=EVAN-PC\\SQLEXPRESS;Initial Catalog=AccufloMaster;Integrated Security=True;User ID=sa;Password=creative";
                System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter(sql, connectionString);
                report.DataSource = adapter;
                report.Name = "recipientReport";
                return View(report);

    However, After I have the report created, how do I view it using the MVC report viewer (which I already have set up). Are there some additional properties I need to set? Ideally, I thought I could just pass the entire Report object to the view and into the viewer, but there is no overlord for that. So once I have the report created programmatically (I have to do this for reasons beyond this thread), how I can view it in the report viewer?

    @model Telerik.Reporting.Report
    @using Telerik.Reporting.Examples.CSharp
        ViewBag.Title = "Telerik HTML5 Report Viewer MVC Demo";
    @section styles
            #reportViewer1 {
                position: absolute;
                left: 5px;
                right: 5px;
                top: 5px;
                bottom: 5px;
                overflow: hidden;
                font-family: Verdana, Arial;
        <link href="@Url.Content("~/ReportViewer/styles/telerikReportViewer-")" rel="stylesheet" />
        var typeReportSource = new TypeReportSource() { TypeName = typeof(ReportCatalog).AssemblyQualifiedName };
       // typeReportSource.Parameters.Add("OrderNumber", Model.SelectedInvoice);
        //ReportSource(new UriReportSource() { Uri = "Product Catalog.trdx" })
            // Each report viewer must have an id - it will be used by the initialization script
            // to find the element and initialize the report viewer.
            // The url of the service which will provide the report viewer with reports.
            // The service must be properly configured so that the report viewer can
            // successfully communicate with the server.
            // For more information on how to configure the service please check
            // The url for the report viewer template. The template can be edited -
            // new functionalities can be added and unneeded ones can be removed.
            // For more information please check
            // Strongly typed ReportSource - TypeReportSource or UriReportSource.
            // Specifies whether the viewer is in interactive or print preview mode.
            // PRINT_PREVIEW - Displays the paginated report as if it is printed on paper. Interactivity is not enabled.
            // INTERACTIVE - Displays the report in its original width and height witn no paging. Additionally interactivity is enabled.
            // Sets the scale mode of the viewer.
            // Three modes exist currently:
            // FIT_PAGE - The whole report will fit on the page (will zoom in or out), regardless of its width and height.
            // FIT_PAGE_WIDTH - The report will be zoomed in or out so that the width of the screen and the width of the report match.
            // SPECIFIC - Uses the scale to zoom in and out the report.
            // Zoom in and out the report using the scale
            // 1.0 is equal to 100%, i.e. the original size of the report
            // Sets whether the viewer’s client session to be persisted between the page’s refreshes(ex. postback).
            // The session is stored in the browser’s sessionStorage and is available for the duration of the page session.
            // Sets the print mode of the viewer.
    @section scripts
        <!--kendo.all.min.js can be used as well instead of kendo.web.min.js and>
        <script src="@Url.Content("~/ReportViewer/js/telerikReportViewer-")"></script>
        <! - optional, if gestures/touch support is required-->

  2. Evan
    Evan avatar
    5 posts
    Member since:
    Aug 2014

    Posted 07 Oct 2014 Link to this post

    It seems I have carelessly left some connection string information in my post. If an admin could remove that - despite it being irrelevant, I would greatly appreciate it.
  3. KAMIL
    KAMIL avatar
    5 posts
    Member since:
    Aug 2014

    Posted 08 Oct 2014 Link to this post

    Looks like I have simillar problem. Im deserializing report file and then I'm setting up connection string then I can't pass Report object to ReportViewer. How to do this?
  4. Evan
    Evan avatar
    5 posts
    Member since:
    Aug 2014

    Posted 08 Oct 2014 Link to this post

    Kind of sucks. They make it super easy to manipulate the report viewer in web forms, but with MVC, it like you don't have access to anything. It would be nice if the ReportSource just took a report object.
  5. KAMIL
    KAMIL avatar
    5 posts
    Member since:
    Aug 2014

    Posted 09 Oct 2014 in reply to Evan Link to this post

    I managed this situation just by modify global datasource in web.config just before report run. However I'm afraid that it can be not safe - what in situation when few user are trying to run report and each user should use his own datasource connection string?
  6. Stef
    Stef avatar
    3610 posts

    Posted 10 Oct 2014 Link to this post

    Hi everyone,

    You can display customized or dynamically created reports in the HTML5 Report Viewer.

    The HTML5 Report Viewer is a client-side widget served by a running Reporting REST service, which is dedicated to work with the viewer. It is the service that manages the report state and resources. For more details, please check  this forum thread.

    In the thread I explain how the viewer and the required REST service work. At the bottom of the post I mention a custom report resolver, which should be used in cases you need to modify reports additionally. The logic for the report generation can be executed in the custom resolver's Resolve method.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top