I'm using the logic found at
http://blogs.infragistics.com/blogs/mihail_mateev/archive/2011/11/24/how-to-integrate-infragistics-reporting-in-web-applications.aspx
specifically, the method in the blog titled: Server-side export reports using the report exporter
This logic opens up the report in a File Download box for the user to choose Save, Open or Cancel.
I would like to use code to save the report for the user and then email it for them also.
Does anyone have any ideas on how to do this - perhaps how to save the report from the memory stream to the PC's hard drive?
Yes - that did it! Beautiful.
Thanks for all this great help. The users are thrilled to have this automated for them. And it is my goal to please them. :o)
and - Merry Christmas!
Thanks Sylvia,:
Add the following lines after the export.
...
exporter.Export(memoryStream, "PDF");
memoryStream.Flush();
memoryStream.Position = 0;
And change the Media Type for:
Dim ATTACHMENT As New Attachment(memoryStream, "test.pdf", "application/pdf")
That should make it work.
Please let me know how it goes.
Regards,
Miguel.
Yes - I used the FileStream logic to save the file to the server and then am emailing it from there - which meets my needs.
It would be nice to know though what I did wrong with the code when trying to email it directly from the memory stream. Perhaps I'm missing a step?
Protected Sub Export()
Dim reportUri = New Uri("Bucher Browser;component/ProtoWS.igr", UriKind.Relative)
Using exporter = ServerExporterFactory.CreateExporter(reportUri)
Dim memoryStream = New MemoryStream()
' Set parameters in exporter
Dim myprotonbr = New Infragistics.Reports.ParameterValue()
' Parameter Name used in the Report Design (.igr file)
myprotonbr.Name = "ProtoNbr"
' Parameter Value
myprotonbr.Value = txtOrdnbr.Text
Dim parameterList As IEnumerable(Of Infragistics.Reports.ParameterValue) = New List(Of Infragistics.Reports.ParameterValue)() From {myquotenbr}
Dim filename = txtCusnam.Text.Trim & "-Proto" & txtOrdnbr.Text.Trim & ".pdf"
exporter.Parameters = parameterList
exporter.Export(memoryStream, "PDF")
Dim sndmsg As String = ""
Dim emailfrom As String = "sylvia.veal@bucherhydraulics.com"
Dim recipient As String = "sylvia.veal@bucherhydraulics.com"
Dim subject As String = "testing"
Dim body As String = "testing email of infragistics report"
Dim mailsrvr As String = "s5006001.bucherhydraulics.com"
Dim SMTP As New SmtpClient
SMTP.Host = mailsrvr
Dim MAIL As New MailMessage(emailFrom, recipient, subject, body)
Dim ATTACHMENT As New Attachment(memoryStream, "test.pdf", "application/vnd.pdf")
MAIL.Attachments.Add(ATTACHMENT)
Try
SMTP.Send(MAIL)
sndmsg = "Email sent successfully"
Catch ex As Exception
sndmsg = ex.Message
End Try
memoryStream.Close()
End Using
End Sub
I see, there might be a problem when configuring the content type , can you show us that part of your code?
Can you try saving it to a local file to discard any problem with the report exporter configuration?
By the way, you can use a FileStream directly to save exported reports as files.
// Use a FileStream if you want to save it as a file directly.
FileStream stream = File.OpenWrite(@"C:\test\myfile.pdf");
exporter.Export(stream,"PDF");
stream.Close();
This is very helpful indeed.
I was able to email the report without error msg - but then when I try to open the attached report from within the email, Adobe Reader gives this error: "Adobe Reader could not open 'test.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).
I googled and found instructions to un-check the 'Display PDF in Browser' box; but that hasn't helped either.
Any ideas?