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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is this possible 3

Status
Not open for further replies.

jshurst

Programmer
Oct 27, 2004
1,158
US
I would like to have a button on a Windows form (vb.net) and when clicked I would like a report to be generated, exported to .pdf format, and then emailed to certain people. Is there a way to do this using reporting services, if not does any one have any suggestions?

Thanks in advance.
 
I think it may be, but I haven't ever delved to that level of automation. You couldn't set any "automatic-pdf-email" stuff from Reporting Services basic UI... you would have to get into code. Unfortunately, the documentation I have seen is sorely lacking in detail when it comes to customized coding.

Sorry I can't be of more help.
 
When a report is pulled up via Reporting Services, it has its own export option. Depending on how parameters may be set, it might render first in HTML or you might be able to export the report straight to PDF. This is, unfortunately, the only PDF functionality with RS that I know of.

I don't know enough about VB code to know if there's some sort of connection/export object you could use to do this directly from some other window. You might check with Microsoft and see if they have a run-time only environment for RS. Crystal has one where they can do almost what you're describing.

However, given all the work MS has supposedly put into this for the next version (they are updating Visual Studio too, I understand), this may change.

Contact MS and ask them about runtime environment functionality.



Catadmin - MCDBA, MCSA
"If a person is Microsoft Certified, does that mean that Microsoft pays the bills for the funny white jackets that tie in the back???
 
WoooHooo. I got it working. For anyone interested here is what I did...

I call the reporting services web service to render the file to pdf, then write that file to a location (easiest way is to keep it on the same server). I then created another web service to mail a message and the newly created file to whomever I choose. The web service could use a little work, but nothing big. I am super happy!

The Button
Code:
 Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click


        'creating an new instance of the web service
        Dim rs As New ReportingService.ReportingService


        'setting the credentials to the machine that this application is running on
        rs.Credentials = System.Net.CredentialCache.DefaultCredentials


        'getting the available reports
        Dim items() As ReportingService.CatalogItem = rs.ListChildren("/", True)


        'looping through all of the reports and writing them to the combo box (this isn't necessary!)
        Dim cnt As Integer
        For cnt = 0 To items.Length - 1
            cmbReports.Items.Add(items(cnt).Name.ToString())

        Next cnt

        Dim ResultStream() As Byte
        Dim StreamIdentifiers() As String
        Dim OptionalParam As String = Nothing
        Dim filename As String = "Test.pdf"
        Dim optionalParams As ReportingService.ParameterValue() = Nothing
        Dim optionalWarnings As ReportingService.Warning() = Nothing


        'rendering the report as a pdf
        ResultStream = rs.Render("/PATH/ReportName", "PDF", Nothing, "<DeviceInfo><StreamRoot>/RSWebServiceXS/</StreamRoot></DeviceInfo>", Nothing, Nothing, Nothing, OptionalParam, OptionalParam, optionalParams, optionalWarnings, StreamIdentifiers)


        'creating a file to hold the stream
        Dim stream As FileStream = File.Create("C:\whatever" + filename)


        'writing the stream to the file
        stream.Write(ResultStream, 0, ResultStream.Length)
        stream.Close()


        'calling the "Postmaster" web service
        Postmaster.mail()

    End Sub

The Web Service
Code:
<WebMethod(EnableSession:=True)> _
         Public Sub mail()
        
        'creating a new message to be mailed
        Dim Message As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage

        Message.From = "jshurst@woohoo.com"
        Message.To = "someone_else@woohoo.com"
        Message.Subject = "Email with Attachment Demo"
        Message.Body = "This is the main body of the email"

        'creating the attachment
        Dim Attachment As System.Web.Mail.MailAttachment = New System.Web.Mail.MailAttachment("C:\path\filename.doc")

        'Adding the attachment to the message
        Message.Attachments.Add(Attachment)
        'sending the message
        System.Web.Mail.SmtpMail.Send(Message)

    End Sub
 
Hey! That's cool. Thanks for posting the solution! It will help. Wanna write a FAQ on it? @=)

Star for you!!!



Catadmin - MCDBA, MCSA
"If a person is Microsoft Certified, does that mean that Microsoft pays the bills for the funny white jackets that tie in the back???
 
I have never written a FAQ before, but I am willing to do that. I will try to get to it later today. Thanks for all the support. Tek-tips helps me so much daily and if I can give something back then I am happy to do so.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top