on 12-13-2012 3:57 AM
Hi,
I want to export my crystal report to pdf and send a mail programically. Crystal report has 4 parameters and how can i pass these parameters in code...
My code is as follows...
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue
Dim crParamenter_array As New ParamArrayAttribute
Dim cryRpt As New ReportDocument
Dim DefaultPrinterName As String
Dim oPS As New System.Drawing.Printing.PrinterSettings
Dim sFilePath As String
Dim sPath As String
Dim sFileLoc As String
Dim sFileName As String
Try
sPath = Path.GetTempPath()
DefaultPrinterName = oPS.PrinterName
sFilePath = GetCrystalReport(_REPRT_CODE)
sFileLoc = sPath + "Reports\" + _REPRT_CODE + ".rpt"
If sFilePath = String.Empty OrElse sFilePath = Nothing Then
TNotification.StatusBarError("File Not Found.")
Return False
Else
cryRpt.Load(sFileLoc)
End If
If Not SetDbLogonInfo(cryRpt) Then
TNotification.StatusBarError("Database Login Failed.")
Return False
Else
crParameterDiscreteValue.Value = _empid
crParameterDiscreteValue.Value = _month
crParameterDiscreteValue.Value = _parea
crParameterDiscreteValue.Value = _year
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("empid")
crParameterFieldDefinition = crParameterFieldDefinitions.Item("month")
crParameterFieldDefinition = crParameterFieldDefinitions.Item("parea")
crParameterFieldDefinition = crParameterFieldDefinitions.Item("year")
crParameterValues = crParameterFieldDefinition.CurrentValues
' crParameterValues.Clear()
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
cryRpt.PrintOptions.PrinterName = DefaultPrinterName
Dim rep As CrystalDecisions.CrystalReports.Engine.FieldObject = Nothing
'sending report to the printer
'cryRpt.PrintToPrinter(_noOfCpys, False, 1, 100)
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New _
DiskFileDestinationOptions()
Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
' CrDiskFileDestinationOptions.DiskFileName = "c:\" + _rptCode + "_" + _docEntry + ".pdf"
'sFileName = "\\B1devsrv\b1_shr\Attachments\" + _rptCode + "_" + _docEntry.ToString + ".pdf"
sFileName = TSQL.GetSingleRecord("Select AttachPath from OADP").ToString.Trim + _empid + "_payslip.pdf"
CrDiskFileDestinationOptions.DiskFileName = sFileName
CrExportOptions = cryRpt.ExportOptions
With CrExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
.DestinationOptions = CrDiskFileDestinationOptions
.FormatOptions = CrFormatTypeOptions
End With
cryRpt.Export()
If SendMail(_empid.ToString, sFileName) Then
TNotification.MessageBox("Email Sent")
End If
If File.Exists(sFileLoc) Then
' File.Delete(strFileLoc)
End If
End If
Return True
Catch ex As Exception
Throw ex
End Try
I got invalid index as error
hi, Former Member
i try to past your code in my project, but need add reference... .and i dont know the reference that i need to put in the project...
could you say me?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Below is an example of setting the parameter name dockey@ in crystal report.
Just repeat this block of code for each of your parameter.
If Not CRRpt.ParameterFields("dockey@") Is Nothing Then
CRRpt.ParameterFields("dockey@").CurrentValues.Clear()
Dim ParamValue As New CrystalDecisions.Shared.ParameterDiscreteValue()
ParamValue.Value = DocEntry
CRRpt.ParameterFields("dockey@").CurrentValues.Add(ParamValue)
End If
Do note that the ParamValue.Value accepts an object type variable.
You have to supply the correct type for each of your CR params.
Regards
Edy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
7 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.