Capture Print/ExportEnd Event Winforms

6 posts, 1 answers
  1. James
    James avatar
    10 posts
    Member since:
    Apr 2015

    Posted 23 Oct Link to this post

    Hi. I need to add some functionality to my application which needs to be triggered on print or export of a report(created in the standalone report designer). I've seen a page in the Telerik documentation stating the following:

    "Additionally events can't be used with Standalone Report Designer report documents, because the custom code from events is not serialized in reports."

    I've also noticed this behaviour through my own testing.

     

    I'm wondering if there is any way that I can capture when a report is printed or exported from the Telerik Winforms Report Viewer without having to reimplement Windows print/export dialogs.

     

    Thanks.

  2. James
    James avatar
    10 posts
    Member since:
    Apr 2015

    Posted 24 Oct Link to this post

    Okay, so I've realized that I can just call the built-in .Net PrintDialog control to capture whether the user printed the document or not. I will need to capture if it's exported as well.

    Following from this, is there a way I can determine if the user clicked on either the TelerikReportViewer Print or Export buttons, so I can launch my own dialogs? Would I need to track the mouse click and determine where on the control it occurred? It seems like there should be some events on Toolbar clicked that could be captured.

  3. Peter
    Admin
    Peter avatar
    1631 posts

    Posted 25 Oct Link to this post

    Hello James,

    The cited sentence is about the report events. The report viewers support events no matter what kind of Report (ReportSource) is used. For the full list of the available events check out the WinForms Report Viewer API.

    Regards,
    Peter
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  4. James
    James avatar
    10 posts
    Member since:
    Apr 2015

    Posted 25 Oct Link to this post

    Okay, gotcha. Thanks Peter. I tested this again after reading your response and now my breakpoints are being hit. I swear they weren't previously. Oh well, guess I was doing something wrong.

     

    I have a follow up regarding ExportEnd, which I think should be fine for this thread. The PrintEnd fires after I have clicked Print, but when exporting, the ExportEnd gets triggered before the save dialog even appears. I can see the export status form doing things before the file dialog, so I understand why ExportEnd is being triggered, but I specifically need to know if the user actually saved the exported file or not. Having another event to know if the user has actually saved the exported file would be nice. 

     

    Having said that, what are my options? I don't see an event that captures whether the export button has been clicked(which may allow me to override the behaviour). Would I have to inherit the ControlViewer and override the Export button click? I do not know if this is even possible. Any direction would be appreciated. Thanks.

  5. Answer
    Peter
    Admin
    Peter avatar
    1631 posts

    Posted 26 Oct Link to this post

    Hi James,

    Yes the export and print mechanisms are different. ExportEnd is invoked after the report is rendered and before the file save file dialog is opened. Thus my suggestion is to handle the export end event and log if successfully saved as shown in the following code snippet:
    public MainForm()
    {
        InitializeComponent();
        this.reportViewer1.ExportEnd += ReportViewer1_ExportEnd;
    }
     
    private void ReportViewer1_ExportEnd(object sender, ReportViewer.Common.ExportEndEventArgs exportEndArgs)
    {
        exportEndArgs.Handled = true;
        var extension = exportEndArgs.DocumentExtension;
        var fileName = exportEndArgs.DocumentName + "." + extension;
        var filter = "";
        if (!string.IsNullOrEmpty(extension))
        {
            extension = extension.TrimStart('.');
            filter += string.Format("{0} Report (*.{1})|*.{1}|", extension.ToUpper(), extension);
        }
        filter += string.Format("{0} (*.*)|*.*", "All Files");
        using (var dialog = new SaveFileDialog())
        {
            dialog.Filter = filter;
            try
            {
                dialog.FileName = fileName;
            }
            catch (SecurityException)
            {
            }
     
            if (DialogResult.OK == dialog.ShowDialog())
            {
                fileName = dialog.FileName;
                using (var stream = dialog.OpenFile())
                {
                    var documentBytes = exportEndArgs.DocumentBytes;
                    stream.Write(documentBytes, 0, documentBytes.Length);
                    //LOG export successful
                }
            }
        }
    }


    Regards,
    Peter
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. James
    James avatar
    10 posts
    Member since:
    Apr 2015

    Posted 03 Nov in reply to Peter Link to this post

    Okay, great.

    I haven't had time to test this yet, but I assume the exportEndArgs.Handled = True is how the system knows not to popup it's own Save dialog.

    Thanks.

Back to Top