Question Reportviewer control - Export to PDF - default filename

Joined
Mar 18, 2014
Messages
18
Location
Devon, UK
Programming Experience
3-5
Hi.

When a user goes to export out a PDF report of mine using the built-in Export icon in the Reportviewer toolbar.... is it possible to set a default filename?

Regards

Matt
 
Joined
Mar 18, 2014
Messages
18
Location
Devon, UK
Programming Experience
3-5
Managed to sort this myself in the end with the following :

Managed to sort this myself in the end with the following :


PrivateSub btnPDFExport_Click(sender AsObject, e AsEventArgs) Handles btnPDFExport.Click
Dim byteViewer AsByte() = ReportViewer1.LocalReport.Render("PDF")
With Me.SaveFileDialog1
.Filter = "PDF files (*.pdf)|*.pdf"
.FilterIndex = 2
.FileName =
"Early Morning Checklist Report (" & DateTime.Today.ToString("dd.MM.yyyy") & ").pdf"
.RestoreDirectory = True
.ShowDialog()
End With
Try
Dim newFile AsNew System.IO.FileStream(Me.SaveFileDialog1.FileName, IO.FileMode.Create)
newFile.Write(byteViewer, 0, byteViewer.Length)
newFile.Close()

Catch ex AsException
MessageBox.Show("Unable to export PDF report." & ControlChars.NewLine & ControlChars.NewLine & "Additonal information : " & ex.Message, "Export PDF Report", MessageBoxButtons.OK, MessageBoxIcon.Information)
EndTry
EndSub
 

IanRyder

Well-known member
Joined
Sep 9, 2012
Messages
1,130
Location
Healing, NE Lincs, UK
Programming Experience
10+
Hi,

Another option for you is to set the DisplayName of the LocalReport. This then creates a default filename for you when you export the report. i.e:-

ReportViewer1.LocalReport.DisplayName = String.Format("Early Morning Checklist Report ({0})", Today.ToString("dd.MM.yyyy"))


Hope that helps.

Cheers,

Ian
 
Top Bottom