Sunday, February 07, 2010

Programmatic export to PDF from Silverlight application

Ever wanted to export a Telerik report from a Silverlight application?

This is easily accomplished by instantiating the ReportServiceClient class, which plays the role of a proxy to the Telerik Report Service. Use the RenderAsync method of the ReportServiceClient to specify that you want to render the report. This method invokes the respective method on the server (remember that it serves as proxy) that would return the rendered report. Check the code below for more details.

Since we are using an asynchronous method and we do not know when the render would finish, we need to handle the RenderCompleted event. In the RenderCompleted event we get the result from the rendering and decide what to do with it -  in this case write down the report.

An interesting part to note here is that we invoke the ShowDialog method prior to having the rendered report, because the dialog box can only be called from user-initiated code, such as a button's Click event. If ShowDialog is called from code that is not user-initiated, a SecurityException is thrown. More info on SaveFileDialog is available in this MSDN article.

Read more: telerik blogs

Posted via email from jasper22's posterous