none
Help converting infopath client form to pdf and email as attachment RRS feed

  • Question

  • Hi Guys -

    I have a little complicated requirement for my infopath client form, they wanted to open an outlook email and make the current view of the infopath as an attachment but converted as pdf or a word, can you help me guys with this. I can't find out of the box solution so i guess via code (infopath button) will solve my problem but don't know where to start.

    Hope for your guidance. THank you.


    ®©™½¼

    Thursday, May 31, 2012 5:32 AM

Answers

  • i give you a mail code but he work only in full trust

    using System.Net.Mail;
    void SendMail()
    {
    MailMessage m = new MailMessage(); 
    m.From = new MailAddress("some mail adress here");
    m.Subject = "some subject";
    m.Body = "some body text";
    m.To.Add("reciepent mail here");
    m.Attachments.Add(new Attachment("pdf_file_location"));
    string mail_host = "your smtp host server";
    string mail_port ="your smtp port";
    SmtpClient client = new SmtpClient(mail_host, mail_port);
    try
    {
    client.Send(m);
    }
    finally
    {
    m.Dispose(); // before delete files must destroy this object
    File.Delete("pdf_file_location");
    }
    }

    • Marked as answer by jwill92 Friday, June 1, 2012 10:49 AM
    Thursday, May 31, 2012 2:53 PM

All replies

  • hi,

    First method is to send a existing view to mail(not pdf):

     Configure a new Submit Data Connection -> As an e-mail message->Send the form data as an attachement. Add a button and submit to your mail connection.

    Second method: if your form is in Full Trust Security Level use this code to export to pdf format

    this.CurrentView.Export("c:\temp.pdf", ExportFormat.Pdf);
    try to use System.Net.Mail.MailMessage class to send exported file
    Thursday, May 31, 2012 6:51 AM
  • Thanks Alex!

    I tried the submit data connection but it send the form attachment as a xml not pdf/word. The requirement is pdf or word.

    How can i make my infopath  Full Trust Security Level ?


    ®©™½¼

    Thursday, May 31, 2012 9:34 AM
  • A form can run with Full Trust only if the form template is digitally signed with a trusted root certificate or if the form template was installed on the user's computer by using an installation program such as Microsoft Windows Installer (.msi file).

    I tried to make my Form in FULL TRUST but im getting a security pop-up, how can i avoid that?

    Also i noticed that there is a checkbox for Sign Certificate, when i viewed it it says...

    This Root Certificate is not trusted. To enable trust, install this certificate in the Trusted Root Certification Authorities store.

    How to install my certificate, i just created it in the form. Thanks.


    ®©™½¼

    Thursday, May 31, 2012 12:18 PM
  • in IE Options-> Content ->Certificates... button

    I think you must install your certificate on each client computer

    Thursday, May 31, 2012 12:52 PM
  • THanks ALex!

    Is it possible to just attached the pdf generated in this below code to the outlook email programmatically? do you have sample if yes, not pulling it from the C:\ drive

    this.CurrentView.Export("c:\temp.pdf", ExportFormat.Pdf);


    ®©™½¼

    Thursday, May 31, 2012 1:06 PM
  • this.CurrentView.Export can export only on the disk. If you are in full trust you can save pdf on the disk, create a System.Net.Mail.MailMessage object, attach this file and send mail. In the end remove pdf file from disk
    Thursday, May 31, 2012 1:15 PM
  • okay thanks,

    im trying to export the certificates in IE OPtions > COntent > Certificates..

    and try to import it in one of my clients PC

    when i ask him to click the button that will export the pdf in C:\

    it doesn't exported and an error pop-up shows.. do you have idea whats lacking..? thanks

    InfoPath has encountered an error. The operation failed.
    InfoPath cannot export the form.
    Access is denied.

       at Microsoft.Office.Interop.InfoPath.SemiTrust.View.Export(String bstrURL, String bstrFormat)
       at Microsoft.Office.Interop.InfoPath.SemiTrust.ViewObjectWrapper.Export(String bstrURL, String bstrFormat)
       at Microsoft.Office.InfoPath.Internal.ViewHost.Export(String fileLocation, ExportFormat format)
       at RMA_Form.FormCode.btnPrint_Clicked(Object sender, ClickedEventArgs e)
       at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)


    ®©™½¼

    Thursday, May 31, 2012 2:09 PM
  • i just try to generate a new certificate from InfoPath Designer. The certificate generate by Infopath is used to self-sign a e-mail forms. To  obtain a certificate for your code you need to obtain from a certification authority. See image:

    Thursday, May 31, 2012 2:18 PM
  • Thanks for all the help Alex!

    last one though,

    Do you have sample codes or blogs that i can follow for this?

    create a System.Net.Mail.MailMessage object, attach this file and send mail. In the end remove pdf file from disk.

    Thanks a lot.


    ®©™½¼

    Thursday, May 31, 2012 2:42 PM
  • i give you a mail code but he work only in full trust

    using System.Net.Mail;
    void SendMail()
    {
    MailMessage m = new MailMessage(); 
    m.From = new MailAddress("some mail adress here");
    m.Subject = "some subject";
    m.Body = "some body text";
    m.To.Add("reciepent mail here");
    m.Attachments.Add(new Attachment("pdf_file_location"));
    string mail_host = "your smtp host server";
    string mail_port ="your smtp port";
    SmtpClient client = new SmtpClient(mail_host, mail_port);
    try
    {
    client.Send(m);
    }
    finally
    {
    m.Dispose(); // before delete files must destroy this object
    File.Delete("pdf_file_location");
    }
    }

    • Marked as answer by jwill92 Friday, June 1, 2012 10:49 AM
    Thursday, May 31, 2012 2:53 PM
  • Nice!!

    I think it is not possible with SharePoint Online.

    Is it possible? If yes, how?

    Thanks in advance.




    Tuesday, December 27, 2016 1:38 PM
  • Where I have set the above code.
    Wednesday, May 24, 2017 12:07 PM