Solved

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

Posted on 2014-03-12
1
834 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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