C1FlexReport to new Outlook Mail

Posted by: andreas.kren on 19 February 2019, 1:38 pm EST

    • Post Options:
    • Link

    Posted 19 February 2019, 1:38 pm EST

    Hi everyone,

    within an application I have created several simple reports. How can I programmatically open an outlook session, create a mail and write the c1flexreport (rendering) result in the new mail body? Is this possible?

    Thank you.

  • Posted 20 February 2019, 5:17 am EST

    Hi Andreas,

    I think there are two possibilities - both mean that you have to export the report to e.g. PDF and handle the mail creation yourself:

    a) use Outlook interop - https://stackoverflow.com/questions/26424767/add-generated-attachment-to-outlook-email

    b) use MAPI to create a new, unsent outlook mail with attachment: https://www.codeproject.com/Articles/17561/Programmatically-adding-attachments-to-emails-in-C

    Hope this helps

    Wolfgang

  • Posted 20 February 2019, 6:53 am EST

    Hello,

    Andreas, as a FlexReport is rendered in FlexViewer and can be exported to various formats (http://help.grapecity.com/componentone/NetHelp/FlexReport/webframe.html#ExportingReportstoVariousFormats.html), you can generate a document with the report data by performing export operations and further use the generated document in your email as an attachment via code. You can learn about the same from this issue on microsoft forums:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/9293d268-9c14-477f-ade6-dd1a77c96260/sending-email-via-outlook-using-c-and-late-binding?forum=csharpgeneral

    Also, thanks Wolfgang.

    Regards,

    Esha

  • Posted 20 February 2019, 7:25 am EST

    I dont want an attachment in the email.

    Imapi has the clear (current) disadvantage that it works one day and another MS does updates or whatever and it doesnt work, so Interop Automation seems the only way for me 2 go…

    I however wanted to export the c1flexreport result to a html stream(!) (like seen in this tipp https://www.grapecity.com/en/forums/winforms-edition/c1flexreport-rendertostrea_1#c1archivehifor-achieving-t) but it only works for pdf, if i take an htmlfilter it doesnt work…

    Regards

  • Posted 20 February 2019, 7:28 am EST

    does not work

        Me.Cursor = Cursors.WaitCursor
    
        Dim tmpcmdAuftrag As New SqlCommand("Select * From Auftrag (NoLock) Where Auftragsnummer=" & AktAuftragsNummer, Cn)
        Dim tmpdaAuftrag As New SqlDataAdapter()
        Dim tmpdtAuftrag As New DataTable()
    
        tmpcmdAuftrag.Transaction = aAuftragsTrans
        tmpdaAuftrag.SelectCommand = tmpcmdAuftrag
        tmpdaAuftrag.Fill(tmpdtAuftrag)
    
        With Me.cflxRepAuftragsReport
            .Load(System.Windows.Forms.Application.StartupPath & "\" & csFlxRepDateiAuftragsschein, csFlxRepNameAuftragsschein)
            .DataSource.Recordset = tmpdtAuftrag
    
    
            .Render()
    
            Dim afilter As New C1.Win.C1Document.Export.HtmlFilter
            Dim ms As New MemoryStream()
    
    
            afilter.ShowOptions = False
    
            ' afilter.DocumentInfo = .Document
            afilter.Stream = ms
    
            ' .Export(afilter)
            .RenderToFilter(afilter)
    
    
            ComposeOutlookMail(afilter.Stream)
    
  • Posted 20 February 2019, 2:57 pm EST

    If i change from htmlfilter to pdffilter it works (as seen in the example)… ( but i need html for the mail body)

  • Posted 20 February 2019, 3:55 pm EST

    So how has the class Export.HtmlFilter to be used?!

  • Posted 21 February 2019, 6:30 am EST

    Ok, but cant it be done within memory. Without saving to disc, or at least without user interaction at all …?

  • Posted 21 February 2019, 8:01 am EST

    Hi Andreas,

    I observe an issue while exporting report to HTML on stream and have escalated the same to the development team (internal tracking ID: 367926).

    Will get back to you once I receive any information.

    However, you can export a report to an HTML file smoothly, this way:

    Dim htmlfile As New HtmlFilter()
    htmlfile.FileName="Test.html"
    htmlfile.ShowOptions=False
    c1FlexReport1.RenderToFilter(htmlfile)
    

    Regards,

    Esha

  • Posted 21 February 2019, 1:26 pm EST

    I tried this (before my posts) but I got an error …

  • Posted 21 February 2019, 1:35 pm EST - Updated 4 October 2022, 12:57 am EST

    as posted several times it works if I take a pdffilter but not with a htmlfilter:

  • Posted 21 February 2019, 4:38 pm EST

    it depends on the kind of report if the htmlfilter works or not. Simple reports w/o datasource work, when i use a report with a dynamic datasource the htmlfilter produces an “parametre” error. whyever

    I gave up in the meantime, since (manually) html exported reports look completely senseless when set to outlook s htmlbody … so my original idea seems not doable. So I ll switch to the old version of creating an email with an attached pdf…

  • Posted 22 February 2019, 2:05 am EST

    Andreas,

    HtmlFilter seems to work well for reports where data source is set at runtime.

    Please refer the attached application showing the same.

    You can modify the application to replicate the issue and share it back, so that I can see where the issue is observed.

    Thanks and Regards,

    Esha

    prj_FlexReport_Export.zip

  • Posted 2 August 2019, 1:20 am EST

    Hello,

    The issue “FlexReport Html export to stream generates exception: Value cannot be null. Parameter name: path” is fixed with the latest 2019V2 release.

    Please download the builds and verify the same:

    http://prerelease.componentone.com/dotnet40/c1winforms/2019-t2/C1WinForms.4_4.0.20192.375.zip

    Thanks,

    Esha

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels