I have a report which can be viewed in Crystal Report viewer in VS. Client needs to generate a PDF file with a click of a button and the PDF should pop up upon finishing exporting and let the client decide where to save the file.
'vb.net
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.IO
Imports QuoteManager
Imports System.Web
Public Class frmQuoteRptPreview
Private objRpt As rptQuotation
Public Overloads Sub ShowDialog(ByVal objQuoteH As DataTable, ByVal objQuoteD As DataTable, ByVal strService As String, ByVal strSales As String, _
ByVal strQuotedBy As String, ByVal strQuoteRef As String, ByVal parent As IWin32Window)
Dim objDataset As New DataSet
objDataset.Tables.Add(objQuoteH.Copy())
objDataset.Tables.Add(objQuoteD.Copy())
objDataset.Relations.Add("MD", objDataset.Tables(0).Columns("RecID"), objDataset.Tables(1).Columns("QuoteID"))
objRpt = New rptQuotation
objRpt.SetDataSource(objDataset)
objRpt.SetParameterValue(0, strService)
objRpt.SetParameterValue(1, strQuotedBy)
objRpt.SetParameterValue(2, strSales)
objRpt.SetParameterValue(3, strQuoteRef)
crvQuotes.ReportSource = objRpt
' Show the dialog
Me.ShowDialog(parent)
End Sub
Private Sub msExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles msExit.Click
Me.Close()
End Sub
Private Sub msGPDF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles msGPDF.Click
Dim s As System.IO.MemoryStream = objRpt.ExportToStream(ExportFormatType.PortableDocFormat)
Dim fs As System.IO.FileStream
Dim w As System.IO.BinaryWriter
'will generate in the app foot folder
fs = New System.IO.FileStream("Report.pdf", IO.FileMode.OpenOrCreate)
w = New System.IO.BinaryWriter(fs)
w.Seek(0, System.IO.SeekOrigin.Begin)
w.Write(s.ToArray)
w.Close()
fs.Close()
System.Diagnostics.Process.Start(fs.Name)
End Sub
End Class
Hope this is helpful.