Solved

programming  render a report and attach it as a PDF to email

Posted on 2014-03-12
1
792 Views
Last Modified: 2014-03-17
Hello,

I'm working on trying to program report viewer  in Vb.net to create a PDF of a report and attach it to an email.  so far I've come up with two separate parts Creating the PDF to a folder location and attaching a file to an email.  however I really need to construct a way of combining the two together without having to show the report first

 this section is for creating the PDF
Try
            Dim byteViewer As Byte() = ReportViewerWindow.ReportViewer1.LocalReport.Render("PDF")
            Dim saveFileDialog1 As New SaveFileDialog()
            saveFileDialog1.Filter = "*PDF files (*.pdf)|*.pdf"
            saveFileDialog1.FilterIndex = 2
            saveFileDialog1.RestoreDirectory = True
            Dim newFile As New FileStream("C:\Users\username\SkyDrive\Documents\test1.pdf", FileMode.Create)
            newFile.Write(byteViewer, 0, byteViewer.Length)
            newFile.Close()
        Catch ex As Exception
            MsgBox(Err.Description, MsgBoxStyle.Exclamation)
        Finally

            AttachPDF()
        End Try
    End Sub

'''-------------------------------------------------------------- This section is for attaching a file to an email 
    Private Sub AttachPDF()
        Dim oOApp As Microsoft.Office.Interop.Outlook.Application
        Dim oOMail As Microsoft.Office.Interop.Outlook.MailItem
        Dim oAddSig As Microsoft.Office.Interop.Outlook.Inspector

        Try
            'Create the Application
            oOApp = CreateObject("Outlook.Application")
            oOMail = oOApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
            oAddSig = oOMail.GetInspector
            'Send the E-Mail to the Recipient
            With oOMail
                .To = "whoever@outlook.com"
                .CC = ""
                .Subject = "Invoice"
                .Body = "Please find attached invoice"
                .Attachments.Add("C:\Users\username\SkyDrive\Documents\test1.pdf")
                .Send()

                MsgBox("And Email has been sent to")

            End With
        Catch ex As Exception
            MsgBox(Err.Description, MsgBoxStyle.Exclamation)
        End Try

Open in new window

0
Comment
Question by:lincstech
1 Comment
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
ID: 39925041
Create a unique ID for pdf file, save it as a global variable. Remove save as dialogs, just save to the user's my documents or maybe even temp folder, and directly attach to email with the earlier generated name/global variable.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short film showing how OnPage and Connectwise integration works.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now