Attachments - InfoPath Dev
in

InfoPath Dev

Attachments

Last post 03-21-2006 06:58 AM by nukkumatti. 13 replies.
Page 1 of 1 (14 items)
Sort Posts: Previous Next
  • 02-14-2006 12:36 AM

    Attachments

    Hi all,

    in my situation it is really not recommended to attach the required files to the InfoPath document. I would rather like to have a browse button in my document with which I can browse my hard drive, select the required files and then send them via email to the next user (or save them to a server). After submission the Infopath document it self then starts a new K2 workflow. That is actually the reason why the attachments within the form are not doable. I am using managed code. Does someone has a good idea or a best practice for that ?

    Thx

    Listen to Motörhead cos they play Rock'n Roll :)
    Listen to Motörhead cos they play Rock'n Roll :)
  • 02-14-2006 04:55 AM In reply to

    Hi all,

    kind of answering my on post. I think I am on the right track.
    This is what I have so far:
    One button with the functionality to browse your local file system (code below):
    [InfoPathEventHandler(MatchPath="CTRL1_5", EventType=InfoPathEventType.OnClick)]
    public void CTRL1_5_OnClick(DocActionEvent e)
    {
    IXMLDOMNode nodeText = thisXDocument.DOM.selectSingleNode("my:myFields/my:field1");
    // Write your code here.
    OpenFileDialog ofdlg = new OpenFileDialog();
    ofdlg.InitialDirectory = @"c:\" ;
    ofdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;
    ofdlg.FilterIndex = 2 ;
    ofdlg.RestoreDirectory = true ;
    if(ofdlg.ShowDialog() == DialogResult.OK)
    {
    nodeText.text = ofdlg.FileName ;
    }
    }

    One textbox where the filename is entered.

    One button to send the email, but its not working yet.
    Some error like access to CDO object failed (code below):
    [InfoPathEventHandler(MatchPath="CTRL3_5", EventType=InfoPathEventType.OnClick)]
    public void CTRL3_5_OnClick(DocActionEvent e)
    {
    // Write your code here.
    IXMLDOMNode nodeText = thisXDocument.DOM.selectSingleNode("my:myFields/my:field1");
    MailMessage objMail = new MailMessage();
    objMail.BodyFormat = MailFormat.Html;
    objMail.From = "name";
    objMail.To = "address";
    objMail.Subject = " text";
    objMail.Body = "text";
    MailAttachment mailAtt = new MailAttachment(nodeText.text);

    try
    {
    SmtpMail.SmtpServer = "IP";
    SmtpMail.Send(objMail);
    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.Message);
    }
    }


    Listen to Motörhead cos they play Rock'n Roll :)
    Listen to Motörhead cos they play Rock'n Roll :)
  • 02-14-2006 06:59 AM In reply to

    Ok got it now,

    this
    objMail.From = "valid email address";

    must be a valid eMail address and also the next line was missing,

    objMail.Attachments.Add(mailAtt);

    That's it. Maybe someone wants to do the same. Hope this can help then.

    Listen to Motörhead cos they play Rock'n Roll :)
    Listen to Motörhead cos they play Rock'n Roll :)
  • 02-14-2006 01:19 PM In reply to

    Thanks posting the answer, this should be helpfull for many more people.

    Agni
    INFOPATHdev India
  • 02-14-2006 09:09 PM In reply to

    Wow. Toooo good.
    Thanks a lot Nukkumatti.
    regards,
    Abhishek
  • 02-15-2006 04:54 AM In reply to

    Ok,

    now I need some help. How is it or better is it possible to have submit button using data connection to send the form via eMail and in addition have some other attachments in the eMail. (The one I selected with the browse button from my file system) or the other way is it possible to programmatically attach the Infopath form to an eMail.

    Thx

    Listen to Motörhead cos they play Rock'n Roll :)
    Listen to Motörhead cos they play Rock'n Roll :)
  • 02-15-2006 12:50 PM In reply to

    You can send you form as an attachment by using a Email dataconnection. You can do this by just giving the attachment name to the email control. But I dont think we can send external files as attachments sent through the InfoPath Email adapter. Only thing you can do is send other files as part of your form, attached through a filecontrol.

    Agni
    INFOPATHdev India
  • 02-16-2006 05:15 AM In reply to

    Hi,
    To use OpenFileDialog Class, we need to add the System.Windows.Forms.dll reference and the namespace.
    Now if I try to run,I get the error stating...
    'Application' is a ambiguous reference.
    Any help???

    Regards,
    Abhishek
  • 02-19-2006 10:51 PM In reply to

    Hi,

    oh yes I forgot to mention it. Sorry for that.
    You need to initialize it like that:

    private Microsoft.Office.Interop.InfoPath.SemiTrust.Application	thisApplication;
    .

    same goes for "app" in the _Startup method.

    That should work I hope.

    Listen to Motörhead cos they play Rock'n Roll :)
    Listen to Motörhead cos they play Rock'n Roll :)
  • 03-20-2006 04:36 AM In reply to

    Hi I asked that already i this thread here but it just got lost somehow.
    Does someone know if I can attach the InfoPath form itself to an eMail programmatically ?

    Thx
    Listen to Motörhead cos they play Rock'n Roll :)
  • 03-20-2006 08:59 AM In reply to

    When you say attach the InfoPath form itself are referring to the .xsn file? Or the .xml file with instance data?

    Also, I noticed in your original thread that you want to allow the user to attach files to the InfoPath form. From a K2 perspective that is NOT good practice. Read thishttp://forum.k2workflow.com/viewtopic.php?t=699

    As well, if you are capturing files in your InfoPath form and then you want to extract them you will have to do some extra work. Can provide you some code if you need it...
    Jason
    http://www.k2distillery.com/
  • 03-20-2006 11:43 PM In reply to

    Hi aspa,

    yes I read this thread already about K2 and too big file attachments within InfoPath, therefor I use the code I posted here already to just send the attachments with a kind of notification mail which is not using the K2 workflow. Anyway I also found the solution for issue from yesterday.

    You can use this code in a button event to include the form as html within the e-mail body as well it is attached to the mail. Actually for me it would be enough to have it in the body, so if someone knows how to avoid the attachment while using this code please let me know.
    MailEnvelope myMail = thisXDocument.View.Window.MailEnvelope;
    myMail.To = nodeOrgMail.text;
    myMail.Subject = "Update information about running ARF Request";
    myMail.Visible = true;
    Listen to Motörhead cos they play Rock'n Roll :)
  • 03-21-2006 06:46 AM In reply to

    On the last K2 project I did I had a process that was using both InfoPath and Asp.Net and I needed a central place to store associated files. I used K2's WSS webservices to create uniquely named folders dynically in WSS. Then I created a central web service that both InfoPath and Asp.Net would call to upload files to that folder in WSS. Then when the user opened a worklist item in either InfoPath or Asp.Net, I read the list of files from the folder in WSS and provided a link to the file. This gave the appearance that the file was actually attached but the file was actually in WSS.
    Jason
    http://www.k2distillery.com/
  • 03-21-2006 06:58 AM In reply to

    Ok that is really a nice solution.

    But I guess I won't have the time anymore to implement that cos I am almost at the end of my thesis time. So I found also a solution may be not as smart as yours :) but it works. May be I'll come back to you again when I start working on my next K2 project.
    Cheers
    Listen to Motörhead cos they play Rock'n Roll :)
Page 1 of 1 (14 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.