Solved

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

Posted on 2014-03-12
1
776 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

759 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

19 Experts available now in Live!

Get 1:1 Help Now