Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-03-12
1
Medium Priority
?
913 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 36

Accepted Solution

by:
Kimputer earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Hi, In my previous Article  (http://www.experts-exchange.com/Database/Reporting/A_15199-Introduction-to-Microstrategy.html)I discussed some basic understanding of Microstrategy that how we can get in Intro of Microstrategy (MSTR). Now it's tim…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

704 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