Skip to Content

Before getting to the nitty gritty of this blog, please note that Crystal Reports (any version, including CRVS 2010 – currently in Beta) has not been tested with Silverlight and thus is not supported. E.g.; if you find  issues, Support will not be able to submit these to QA for a resolution. TS will try to help, though even this help will be limited to known solutions outside of Silverlight.

In the next release of Crystal Reports for .NET 2010 (CR for VS2010, also known as CRVS2010 and CR2VS2010), there will be a WPF viewer available to embed Crystal Report reports viewing in WPF applications.   However, this WPF viewer will not work with Silverlight apps.  WPF and Silverlight apps are slightly different type of applications support is only provided for WPF projects.

The below is a shameless plagiarism (copy / paste) of a blog I found at the following link:
http://www.global-webnet.net/blogengine/post/2009/01/06/Running-Crystal-Reports-from-Silverlight.aspx

Ok, ok, it’s not that bad. I do have the permission of Bill Kratochvil, the author of the blog to duplicate the content here. Only reason I decided to essentially duplicate the content is so that the knowledge is preserved. E.g.; if the above is removed, we loose lots of great, great info. And I have no control over somebody else’s published content. However I do have some control over content published on these pages. I love information and I hate to loose it just as much or more. Call me paranoid, but I love the blog and don’t want to loose it.

Running Crystal Reports from Silverlight

The following www.Silverlight.net webcast HTML BROWSER INTEGRATION (http://silverlight.net/learn/learnvideo.aspx?video=65683) provides the key to running Crystal Reports from Silverlight.  Once you complete

the webcast you’ll find it takes only a few steps to get your Crystal Reports up and running.

I downloaded the C# Source code from the above referenced link, added the following class (MyClass) to the HtmlInteraction_CS project’s Page.xaml.cs file and updated the Button1_Click() to support it:

///

/// Added Inner class for proof of concept
///

public class MyClass

{
    public string ReportName { get; set; }
    public int ID { get; set; }

    ///

    /// Override ToString so we can easily return our
    /// URL Parameters
    ///

    ///

    public override string ToString()
    {
        return string.Format(“?ID={0}&Name={1}”, ID, ReportName);
    }
}

///

///
///

///
///

private void Button1_Click(object sender, RoutedEventArgs e)

{
    // Instantiate class setting ReportName to textbox value
    MyClass para = new MyClass
    {
        ID = 10,
        ReportName = TextBox1.Text
    };

    // Invoke the sayGoodbye javascript method

    HtmlPage.Window.Invoke(“sayGoodbye”,

        new string[] {para.ToString()});
}

 

With my Silverlight code completed I only needed to prepare the Website code.  I renamed the testpage to CrystalReportPrototype.aspx and added the window.open(“Report.aspx”+fname, “_blank”) to the sayGoodbye(fname) javascript method as shown below:

 

So all that remained was to create my Report.aspx and reports.  I dropped a CrystalReportViewer object on the page and named it Demo1.  I then parse out the “Name” and run the applicable report, i.e.,

DemoReport (default), DemoReport1 and DemoReport2.

After I saw all was well I used Expression Blend to spiffy up the Silverlight screen (took all of five minutes):

A WebCast of the above can be found here:
http://www.global-webnet.net/Webcast/SilverlightCrystalReport.wmv

Related information:
http://www.redmondpie.com/incorporate-crystal-reports-in-a-c-wpf-application/

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Azadeh Kh
    Hi,

    Thank you for this great solution but unfortunately this solution ( Using HtmlPage.Window.Invoke)  doesn’t work in  out of browser(OOB) mode in Silverlight!

    Any Idea?

    Thanks,

    (0) 

Leave a Reply