Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
380
Generic WPF Window Report Viewer
posted

I wanted to create a generic report viewer that I could pass any relative report path as a parameter and the report would be displayed, using syntax something like the following

 

 

 

 

string relativePath = "/Report Library;component/Trial Report.igr";

 

 

 

//Instantiate the generic report viewer

ViewerWindow vw = new ViewerWindow(relativePath);

vw.Show();

Taking ideas from the reporting basics, I created a WPF window (named ViewerWindow) and added a XamReportViewer (named xamReportViewer1), and in the code behind, added a using directive (using Infragistics.Controls.Reports;) and added an additional constructor:

 

 

 

 

 

 

public ViewerWindow(string reportPath)

{

 

InitializeComponent();

 

 

 

 

 

Uri uri = new Uri(reportPath, UriKind.Relative);

 

 

ClientRenderSettings settings = new ClientRenderSettings();

settings.DefinitionUri = uri;

xamReportViewer1.RenderSettings = settings;

}

And no other code was necessary. I used the code calling code that I described at the outset, and it worked! No more hard coding the DefinitionUri in the Xaml; one report viewer to display any NetAdvantage report!

Hope others find this useful--or maybe help to stir up a better idea.  If anyone would like to see the actual code behind, please see attached text file.

  • 280
    posted

    Hi


    Let's say I would want to do this exactly like you said with an adjusted report. I read an IGR with an XML reader, manipulate the content to a point and would like to use the result to display my data. I could erase some sections, add columns to a table, change the display color of a line series, or similar things.


    I would like to either safe the report to a place and tell the report viewer where to find it, or take the definition directly and stream it into the viewer. Unfortunately both are tricky to put into the real.


    For the stream I found no entry point yet to shove it into the context of the viewer at all. So then I tried to save the report to the hard disk and call it from there. That would have been a great idea, when I would be able to save the report directly into the program directory relatively to the running program itself. A regular user will not have this kind of rights to safe or alter data in that place. So I tried to safe it directly in the user path, which was a great idea to be able to safe it, but a bad place for putting it into the report viewer. The ClientRenderSettings seem to gulp without any problems relative URIs, but an absolute one seems to cause major tummy aches.


    I thought, since you took a similar route with the generic ReportViewer you might have come across one or two of these tripping hazards and probably found a solution.


    Wish you a nice day.
    Enrico