Blogs

The One With

End-User Report Designer – Viewing Reports (Part 2)

     

XtraReports™ SuiteIn part 1 we created an end-user report designer that can publish reports to a database using OData protocol. Now, let’s create a Silverlight application that can view the reports that we have published.

Report Service

First we’ll add a printing service to our ASP.NET host application.

Silverlight-enabled XtraReports Service

By default Silverlight-enabled XtraReports Service looks up the reports by type name, we want to override this behavior and load the report from the database.

protected override XtraReport CreateReport(
    string reportTypeName, 
    Dictionary<string, object> parameters) {
    
    try {
        using (List listService = new List()) {

            using (Session session 
                        = new Session(listService.GetDataLayer())) {

                Report report 
                    = session.GetObjectByKey<Report>(new Guid(reportTypeName));

                if (report == null) {
                    return Create404Report();
                }

                File file = report.File;

                if (file == null) {
                    return Create404Report();
                }

                XtraReport retVal = new XtraReport();

                using (MemoryStream stream = new MemoryStream(file.Binary)) {
                    retVal.LoadLayout(stream);
                    return retVal;
                }

            }
        }
    } catch (Exception e) {
        return Create500Report(e);
    }
    
}

Note: The assumption of the new CreateReport is that the reportTypeName is a report ID, a GUID.

Silveright Viewer

Inside the Silverlight, we’ll simply drop the DocumentPreview control on our page and load the report on page load. I have described this process here.

<dxp:DocumentPreview Name="documentPreview1"/>

void MainPage_Loaded(object sender, RoutedEventArgs e) {
    if (!HtmlPage.Document.QueryString.ContainsKey("id")) {
        return;
    }
    
    string reportId = HtmlPage.Document.QueryString["id"];

    if (string.IsNullOrWhiteSpace(reportId)) {
        return;
    }

    ReportPreviewModel model
                   = new ReportPreviewModel(
                        new Uri(App.Current.Host.Source.AbsoluteUri + "../../ReportService.svc").ToString());

    model.ReportTypeName = reportId;

    documentPreview1.Model = model;

    model.CreateDocument();
}

That’s it, we can now access our reports by a URL for example

http://localhost.:56844/Report.aspx?id=7750954ac4b749a2a41c70f419e741c2

Silverlight Report Viewer

Final Notes

  • You can download the complete sample here.
  • The included Web.config will be useful to you if you need to copy paste some settings.
  • You will also need DevExpress.Xpo.Services.10.1.dll this file is not included in the provided sample but you can download it from http://xpo.codeplex.com.
  • Get more information and more samples of OData Provider for XPO.

Cheers

Azret

Published Aug 24 2010, 09:37 PM by Azret Botash (DevExpress)
Technorati tags: Silverlight, XtraReports, XPO, Reports, OData
Bookmark and Share

Comments

No Comments
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.