Quantcast
Channel: Crystal Reports
Viewing all articles
Browse latest Browse all 1507

Emailing Crystal Report

$
0
0

I'm a complete noob when it comes to Crystal Reports and i really need some help with a solution.  I basically want a Crystal Report in where when it has been generated.  I would want to email it to a customer.  How do i do this with a textbox in where i enter the customers email address and a button which then emails the report.  As i have said i am a novice when it comes to this so clear explanation would be muchly appreciated. 

Also, when i say clear i need to know at which point the report is emailed, eg, is it at a button press or when he page is loaded from a previous button press.  Also need to know the coding from start to finish.  I have got as far as knowing that i have to type in 'Imports System.Net.Mail in the top part of the code..The rest is a mystery to me.  Here is my code so far.  I have a report in where when a user types in an Invoice number and presses the button an Invoice is produced.  I want another button underneath that so when the user is ready to email the Invoice to the customer, all the user has to do is Enter the email address in a text box and then press a button.  Is it as simple as that????  Also, does anything need to go into Web.config as well in order for me to send mail?

Here is my current code:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports
System.Net.Mail
Partial Class Default2
    Inherits System.Web.UI.Page
    Dim cryRpt As New ReportDocument

    Protected Sub Button1_Click(ByVal senderAs Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cryRpt As New ReportDocument
        cryRpt.Load("C:\Documents and Settings\xxxxxxxxxxxxxxxxxx\My Documents\Visual Studio 2005\WebSites\Invoices\CrystalReport3.rpt")
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue
        crParameterDiscreteValue.Value = TextBox1.Text
        crParameterFieldDefinitions = _
        cryRpt.DataDefinition.ParameterFields
        crParameterFieldDefinition = _
        crParameterFieldDefinitions.Item("InvoiceNo")
        crParameterValues = crParameterFieldDefinition.CurrentValues
        crParameterValues.Clear()
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
        CrystalReportViewer1.ReportSource = cryRpt
        CrystalReportViewer1.RefreshReport()
    End Sub
End Class

I have searched the forums but none of it makes sense to me.  Have also looked at David Wantu's system.net.mail website and have also looked at the new asp video, i can understand it to a certain extent but get confused on when things are executed and what the structure of the coding should be... [:S]

 Please Help.

 Regards, Jonah


Viewing all articles
Browse latest Browse all 1507

Trending Articles