title: Exporting crystal report to pdf
body: <p>I want to know about how to export crystal report with 4 parameters by code. and  i tried the following code and "invalid index error' is returned.</p>
  
  <pre><code>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 
  </code></pre>