cancel
Showing results for 
Search instead for 
Did you mean: 

How to export PDF & attached it in Email using DI API

0 Kudos

Hi Everyone,

I did coding to send email after adding document in C#. Now I don't know how to export pdf of that document & attached it to email. I tried some solutions but didn't work. I have a PLD & Crystal reports layout ID. Using that ID , I want to export report of recently created document & attached it in to email. Please suggest me with some sample example or any alternate way.

Thanks!

former_member8821
Active Participant
0 Kudos

nansz_22

if you need any support or guide then sure you will update me.

Accepted Solutions (1)

Accepted Solutions (1)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi nansz_22,

Refer to the sample code in SAP Note 2966187.

Email part you need to implement yourself.

Kind regards,

ANKIT CHAUHAN

SAP Business One Support

0 Kudos

Hi ankit.chauhan1 ,

I'm not able to access SAP Note 2966187.

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert

Hi nansz_22,

Below is the code from the mentioned SAP Note:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
 
     Try
            Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
            'Database information
            Dim userId As String = "Database Userid"
            Dim password As String = "Database Password"
            Dim serverName As String = "Database Server:port"
            Dim Database As String = "Databasename"
   'For HANA 32 bit B1CRHPROXY32 or HDBODBC32
   'For HANA 64 bit B1CRHPROXY or HDBODBC
   'For MSSQL 32/64 bit "SQL Server Native Client 11.0" or SQLNCLI11
            Dim Provider As String = "B1CRHPROXY32"
            'Parameters information based on the report which you use
            Dim param1 As String = "C20000"
            'Location of the report .rpt located in the same path of the exe,else provide full location.
            rpt.Load("OCRD_HANA_Params.rpt")
            rpt.DataSourceConnections.Clear()
            'Connection String.Use the same structure.
            Dim strConnection As String = String.Format("DRIVER={0};UID={1};PWD={2};SERVERNODE={3};DATABASE={4};", "{" + Provider + "}", userId, password, serverName, Database)
            'Set Database login inputs for the reports
            Dim logonProps2 As NameValuePairs2 = rpt.DataSourceConnections(0).LogonProperties
            logonProps2.Set("Provider", provider)
            logonProps2.Set("Connection String", strConnection)
            rpt.DataSourceConnections(0).SetConnection(serverName, Database, False)
            rpt.DataSourceConnections(0).SetLogon(userId, password)
            'Set login info in subreports.
            For Each subr As ReportDocument In rpt.Subreports
                For Each conn As CrystalDecisions.Shared.IConnectionInfo In subr.DataSourceConnections
                    conn.SetConnection(serverName, Database, False)
                    conn.SetLogon(userId, password)
                Next
            Next
            'Set Parameters
            rpt.ParameterFields(0).DefaultValues.Clear()
            rpt.SetParameterValue(0, param1)
            'Export to disk  
    rpt.ExportToDisk(ExportFormatType.PortableDocFormat, Provider + "_" + Guid.NewGuid().ToString() & ".pdf")
            rpt.Close()
            MsgBox("Report export successfull!.Check " + Provider + "_" + Guid.NewGuid().ToString() & ".pdf")
        Catch ex As Exception
            'Console.WriteLine("DB_Report with Parameters")
            MsgBox(ex.Message)
        End Try

Kind regards,

ANKIT CHAUHAN

SAP Business One Support

0 Kudos

Hi ankit.chauhan1 ,

Can we change export to disk path? Files are getting exported in bin location of project. I want to export in attachment folder of SAP.

Thanks!

Answers (1)

Answers (1)

former_member8821
Active Participant
0 Kudos

nansz_22

Please open SAP note with T-Code SNOTE

and If you are not able to access SAP Note 2966187 then please you will cordinate with your basis team, i am sure they will help you for open this SAP Note.

Hi,

Ok, will try & let you know