0

I'm using ReportViewer and I'm looking to listen to the result of the exports. I would like to get a callback on the export details (filename and filepath). I googled around and was only able to find the reportviewer.export event but that's an event that is triggered before the export. I'm looking for something afterwards. Any tips would be greatly appreciated.

Master
  • 2,038
  • 2
  • 27
  • 77
  • [ReportViewer - Export report programmatically to a specific location without showing save dialog](http://stackoverflow.com/questions/40409033) – Reza Aghaei Nov 11 '16 at 21:50

1 Answers1

1

You could implement your own ReportExport event in order to add functionality after the export.

This is an example in VB.NET:

Private Sub ReportViewer1_ReportExport(sender As Object, e As Microsoft.Reporting.WinForms.ReportExportEventArgs) Handles ReportViewer1.ReportExport

    e.Cancel = True 'stop the default ReportExport event

    Dim strExtension As String = ""

    Select Case UCase(e.Extension.Name)

        Case "PDF"
            strExtension = ".pdf"

        Case "EXCEL"
            strExtension = ".xls"

        Case "WORD"
            strExtension = ".doc"

    End Select

    Dim dlgSaveFile As New System.Windows.Forms.SaveFileDialog

    dlgSaveFile.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
    dlgSaveFile.Filter = e.Extension.LocalizedName + " (*" + strExtension + ")|*" + strExtension + "|All files(*.*)|*.*"

    If dlgSaveFile.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then

        Me.ReportViewer1.ExportDialog(e.Extension, e.DeviceInfo, dlgSaveFile.FileName)

        'add here your functionality, for example a simple MsgBox that display where file is saved
        MsgBox("File saved in: " & dlgSaveFile.FileName)

    End If

End Sub
tezzo
  • 10,858
  • 1
  • 25
  • 48