WPF Viewer: Display errors in Subreports

  • BernhardB 3 weeks, 2 days ago

    Hi,

    i am using the WPF Viewer of Active Reports (v10.1) to display reports.
    There is always one main report with several, programmatically generated, subreports. If there are errors in the main template, i get an error like “A DataSet referenced in the report ‘DummyDataset’ could not be found”. These errors are always displayed in the viewer. If the error is located in the subreport, i only get the message “An error occurred while attempting to execute the subreport” as text in the report. In this case, the user would have to check every page of the report to find errors.

    Is it possible to display errors in the subreport the same way as errors in the main report ? Is there a way to catch these errors in the code (C#)?

    Thanks

    Bernhard

  • 185p
    AbdiasM185p 3 weeks, 2 days ago

    Hi Bernhard,

    If you wish to catch errors in the Subreports, you would need to use a custom ResourceLocator and use a try catch block to handle the internal error and set it to the MainReport’s ResourceLocator property as below:

    private void Viewer1_Loaded(object sender, RoutedEventArgs e)
            {
                PageReport rpt = new PageReport(new System.IO.FileInfo(“../../Reports/RdlReport1.rdlx”));
                rpt.ResourceLocator = new CustomResourceLocator();
                rpt.Run();
                Viewer1.LoadDocument(rpt.Document);
            }
    
    public class CustomResourceLocator : GrapeCity.ActiveReports.Extensibility.ResourceLocator
        {
            public override Resource GetResource(ResourceInfo resourceInfo)
            {
                string name = resourceInfo.Name;
                var path = @”../../Reports/”;
    
                Uri uri = new Uri(path + name, UriKind.Relative);
    
                System.IO.MemoryStream memory_stream = new System.IO.MemoryStream();
    
                if (name.Contains(“.rdlx”))
                {
                    PageReport pr = new PageReport(new System.IO.FileInfo(path + name));
    
                    try
                    {
                        pr.Run();
                    }
                    catch (Exception ex)
                    {
                        //handle exception here (show message to user, etc)
                        MessageBox.Show(“Error occured in ” + name + ” report\nError message : ” + ex.Message);
                    }
                    finally
                    {
                        using (System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(memory_stream))
                        {
                            pr.Save(writer);
                        }
    
                        memory_stream.Position = 0;
                    }
                }
                return new Resource(memory_stream, uri);
            }

    I have attached a sample application for your reference as well. Hope it is helpful.

  • BernhardB 3 weeks, 1 day ago

    @AbdiasM said:
    Hi Bernhard,

    If you wish to catch errors in the Subreports, you would need to use a custom ResourceLocator and use a try catch block to handle the internal error and set it to the MainReport’s ResourceLocator property as below:
    [...]

    Thanks, this is exactly what i was looking for.

  • 185p
    AbdiasM185p 3 weeks, 1 day ago

    Glad I could help :)

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.