locked
How to get the file path of attached document to attachment control in Infopath 2010 RRS feed

  • Pregunta

  • I have added an attachment control to InfoPath  2010 form. 

    I want File Path of the attached file from where it is browsed.

    Is there any infopath built in function or any programmatic way to get the file path of infopath attachement control.


    viernes, 4 de enero de 2013 9:54

Respuestas

  • Hi nirajzambad,

    There is not "out of the box" way to get what you need without writing code. In addition, if you are using the built-in File Attachment control there is still not a way to get the path of the file selected. There are a couple of options though:

    1) If you are designing an InfoPath Form Template to be used in the InfoPath client, you could use the "OpenFileDialog" from System.Windows.Forms, like this:

    OpenFileDialog ofd = new OpenFileDialog();
    ofd.InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);
    ofd.Title = "Select file to attach...";
    DialogResult result = ofd.ShowDialog();
    if(result == DialogResult.OK)
    {
    string strFileNameAndPath = ofd.FileName;
    string strFileNameOnly = ofd.SafeFileName;
    }

    Obviously this will not be populating the File Attachment control with that file but you could use additional code to "base64 encode" the selected file and populate the File Attachment node. 

    2) If you are designing an InfoPath Form Template to be used in the browser, then you will need to host your InfoPath form template in a custom ASPX page (http://msdn.microsoft.com/en-us/library/aa701078.aspx) and use the ASP.NET "FileUpload" control to perform the same basic steps as above.

    Once again, this will not populate the File Attachment control on your form but you can do the same thing: "base64 encode" the selected file and the set the File Attachment node in your form.

    The following article provides sample code to encode/decode a file attachment:

    http://support.microsoft.com/kb/2517906

    I hope this helps!

    Scott


    Scott Heim - Microsoft Office InfoPath and SharePoint Designer Online Community Support

    • Propuesto como respuesta Scott He - MSFT martes, 15 de enero de 2013 21:36
    • Marcado como respuesta NirajZ miércoles, 16 de enero de 2013 4:40
    martes, 15 de enero de 2013 21:36

Todas las respuestas

  • Hi,

    See my reply in below thread. you have to write code to get attachment from the form.

    http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopmentprevious/thread/86ce3949-e22a-4d5b-bf2d-7351c8bc8e38

    Let us know if you have any doubt


    Hemendra: "Yesterday is just a memory,Tomorrow we may never see"

    Whenever you see a reply and if you think is helpful, click "Alternate TextVote As Helpful"! And whenever you see a reply being an answer to the question of the thread, click "Alternate TextMark As Answer

    viernes, 4 de enero de 2013 12:00
  • Thank you Hemendra Sir, 

    but i don't want attachment from the form. i want the location of file added to the attachment control. i want that file path for the following method.

    newMail.Attachments.Add(Source, iAttachType, iPosition, sDisplayName);

    if i get the "source" of file attached to attachment control, i can directly send that attachment to the Outlook.

    viernes, 4 de enero de 2013 12:25
  • Hi,

    There is no URL for attachment because InfoPath attachments are stored as pieces of text called base64 encoded strings within the InfoPath form itself. So you have to follow my first approach to extract attachment from the form then send that attachment file through email.

    If you really want to have URL then you will have to save attchment in document library through code then you can use that library URL. (this approach does not helpful in you case).

    You should also read about infopath attachment:

    http://www.bizsupportonline.net/blog/2010/04/top-10-questions-infopath-file-attachments/

    Let us know if you have any doubt 



    Hemendra: "Yesterday is just a memory,Tomorrow we may never see"

    Whenever you see a reply and if you think is helpful, click "Alternate TextVote As Helpful"! And whenever you see a reply being an answer to the question of the thread, click "Alternate TextMark As Answer

    viernes, 4 de enero de 2013 17:45
  • if i get the file name of attached file then i think there should be something by which file path can be obtained.

    Means if i attach a file from a local machine then on a button click event i want to catch the path of file from where it is attached.

    For Ex: if file name is Image.jpeg from c drive then i should get hte path like this C:\\Image.jpeg

    sábado, 5 de enero de 2013 5:35
  • Hi nirajzambad,

    There is not "out of the box" way to get what you need without writing code. In addition, if you are using the built-in File Attachment control there is still not a way to get the path of the file selected. There are a couple of options though:

    1) If you are designing an InfoPath Form Template to be used in the InfoPath client, you could use the "OpenFileDialog" from System.Windows.Forms, like this:

    OpenFileDialog ofd = new OpenFileDialog();
    ofd.InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);
    ofd.Title = "Select file to attach...";
    DialogResult result = ofd.ShowDialog();
    if(result == DialogResult.OK)
    {
    string strFileNameAndPath = ofd.FileName;
    string strFileNameOnly = ofd.SafeFileName;
    }

    Obviously this will not be populating the File Attachment control with that file but you could use additional code to "base64 encode" the selected file and populate the File Attachment node. 

    2) If you are designing an InfoPath Form Template to be used in the browser, then you will need to host your InfoPath form template in a custom ASPX page (http://msdn.microsoft.com/en-us/library/aa701078.aspx) and use the ASP.NET "FileUpload" control to perform the same basic steps as above.

    Once again, this will not populate the File Attachment control on your form but you can do the same thing: "base64 encode" the selected file and the set the File Attachment node in your form.

    The following article provides sample code to encode/decode a file attachment:

    http://support.microsoft.com/kb/2517906

    I hope this helps!

    Scott


    Scott Heim - Microsoft Office InfoPath and SharePoint Designer Online Community Support

    • Propuesto como respuesta Scott He - MSFT martes, 15 de enero de 2013 21:36
    • Marcado como respuesta NirajZ miércoles, 16 de enero de 2013 4:40
    martes, 15 de enero de 2013 21:36