Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generate and Attach Multiple PDF's to an email

Status
Not open for further replies.

daughtd

Programmer
Sep 6, 2006
15
US
I have created a shopping cart to hold the selected pdf PrimaryID to be emailed to a user. But I'm not sure how to go about creating the selected PDF from data residing in the database and attaching them to an email. I need to pull the data from the database based on the primaryID in the shopping cart(datatable in a session variable) and attach the pdf to the email. I'm new to ASP.NET so any information is deeply appreciated.
 
You could try using Crystal Reports. There are quite a few examples on google and this site if you do a quick search for them.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Since you are new to asp.net this might be a little over your head (no offense ;-) ) but I've written a few FAQ's that could be combined to accomplish this, so here they are...

faq855-5919 Using the SQL Reporting Services Web Service
faq855-5920 Sending an email with Attachment through a web service

You can use the Reporting Services web service to create the file and save it in a location (probably a temp file somewhere), then use another web service (doesn't have to be a web service though) to send the email with an attachment.

Good luck.
 
Well, I sort of had to do the same thing today, so I'm going to make another post...

Anyway, I created a report (a .rdlc file). You need to create a datasource as well for this file (the wizard will create the datasource for you - an .xsd). Then I did the following to create a file in a temporary directory. I put this in the page_load, but I don't really want to open a separate page just for file creation, so I'll probably put it as a sub, or class somewhere.

Anyway, here is the code that I used.

Code:
 Imports System
Imports System.IO
Imports Microsoft.Reporting.WebForms


Partial Class Reports_TemporaryReports
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim ReportViewer1 As New ReportViewer()
        ReportViewer1.ProcessingMode = ProcessingMode.Local
        ReportViewer1.LocalReport.ReportPath = Request.PhysicalApplicationPath & "Reports\ArrestWorkSheet.rdlc"

        Dim myDataSource As New ObjectDataSource("MCCJISSERVICE.MCCJISWebService", "GetArrestWorkSheet")

        Dim parameter As New QueryStringParameter("ArrestNumber", "ArrestNumber")
        myDataSource.SelectParameters.Add(parameter)

        Dim myReportDataSource As New ReportDataSource("DataSet1_Usp_MCCJISWEB_Select_ArrestWorkSheetReport_NEW", myDataSource)

        ReportViewer1.LocalReport.DataSources.Add(myReportDataSource)


        Dim warnings As Warning() = Nothing
        Dim streamids As String() = Nothing
        Dim mimeType As String = Nothing
        Dim encoding As String = Nothing
        Dim extension As String = Nothing
        Dim bytes As Byte()

        bytes = ReportViewer1.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)

        Dim fs As New FileStream(Request.PhysicalApplicationPath & "Reports\TemporaryReports\NewFile.pdf", FileMode.Create)
        fs.Write(bytes, 0, bytes.Length)
        fs.Close()

    End Sub
  
End Class

Also, if you have a problem with the Microsoft.Reporting.WebForms namespace, then add something like the following to the .aspx page...

Code:
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03ffeefeasd"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

Now if I could send this directly to the printer I would be happy, but I'm working on that...
[/code]
 
Oh no offense taken. I feel like my grand father is teaching me how to swim by throwing me overboard about a mile from shore..haha. But I guess thats the best way to learn because I'm learning a lot of other stuff while digging through.

But thanks anyway the info is very useful.
 
Sink or swim! Just kidding, that's what the forum is for...to help you out when you get stuck (and I get stuck all the time - luckily we have some .Net guru's around here).

There might be an easier way, but I don't know it. Just remember, you need some kind of formatting to occur so that you can present it on a PDF, that's why I'm using the reports.

I'd forget my first example (the FAQ's). You'll need to have a reporting services server to use that stuff. My second post should be more helpful - but you'll need to create a report first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top