Solved

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TimeZone, day light savings, Sql server, asp.net 6 38
parsing JSON help 1 20
bound data table problem 2 33
VB.NET Application Installation with sqlserver 8 32
Hi, I am very much excited today since I'm going to share something very exciting Tool used for Analytical Reporting and that's nothing but MICROSTRATEGY. Actually there are lot of other tools available in the market for Reporting Such as Co…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 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